@byline/db-mysql 4.8.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.
Files changed (75) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +283 -0
  3. package/dist/database/schema/auth.d.ts +951 -0
  4. package/dist/database/schema/auth.js +226 -0
  5. package/dist/database/schema/common.d.ts +168 -0
  6. package/dist/database/schema/common.js +130 -0
  7. package/dist/database/schema/index.d.ts +3419 -0
  8. package/dist/database/schema/index.js +895 -0
  9. package/dist/database/schema/schema-pins.test.node.d.ts +52 -0
  10. package/dist/database/schema/schema-pins.test.node.js +398 -0
  11. package/dist/index.d.ts +79 -0
  12. package/dist/index.js +151 -0
  13. package/dist/lib/boot-check.d.ts +22 -0
  14. package/dist/lib/boot-check.js +42 -0
  15. package/dist/lib/boot-check.test.node.d.ts +8 -0
  16. package/dist/lib/boot-check.test.node.js +46 -0
  17. package/dist/lib/db-manager.d.ts +54 -0
  18. package/dist/lib/db-manager.js +49 -0
  19. package/dist/lib/test-db.d.ts +37 -0
  20. package/dist/lib/test-db.js +111 -0
  21. package/dist/lib/test-helper.d.ts +33 -0
  22. package/dist/lib/test-helper.js +68 -0
  23. package/dist/modules/admin/admin-permissions-repository.d.ts +35 -0
  24. package/dist/modules/admin/admin-permissions-repository.js +101 -0
  25. package/dist/modules/admin/admin-preferences-repository.d.ts +62 -0
  26. package/dist/modules/admin/admin-preferences-repository.js +156 -0
  27. package/dist/modules/admin/admin-roles-repository.d.ts +11 -0
  28. package/dist/modules/admin/admin-roles-repository.js +209 -0
  29. package/dist/modules/admin/admin-store.d.ts +20 -0
  30. package/dist/modules/admin/admin-store.js +30 -0
  31. package/dist/modules/admin/admin-users-repository.d.ts +11 -0
  32. package/dist/modules/admin/admin-users-repository.js +303 -0
  33. package/dist/modules/admin/index.d.ts +27 -0
  34. package/dist/modules/admin/index.js +27 -0
  35. package/dist/modules/admin/refresh-tokens-repository.d.ts +34 -0
  36. package/dist/modules/admin/refresh-tokens-repository.js +160 -0
  37. package/dist/modules/audit/audit-commands.d.ts +29 -0
  38. package/dist/modules/audit/audit-commands.js +40 -0
  39. package/dist/modules/audit/audit-queries.d.ts +41 -0
  40. package/dist/modules/audit/audit-queries.js +169 -0
  41. package/dist/modules/counters/counters-commands.d.ts +54 -0
  42. package/dist/modules/counters/counters-commands.js +121 -0
  43. package/dist/modules/counters/tests/counters-concurrency.test.d.ts +8 -0
  44. package/dist/modules/counters/tests/counters-concurrency.test.js +111 -0
  45. package/dist/modules/storage/classify-error.d.ts +34 -0
  46. package/dist/modules/storage/classify-error.js +50 -0
  47. package/dist/modules/storage/classify-error.test.node.d.ts +8 -0
  48. package/dist/modules/storage/classify-error.test.node.js +89 -0
  49. package/dist/modules/storage/normalize-row.d.ts +55 -0
  50. package/dist/modules/storage/normalize-row.js +135 -0
  51. package/dist/modules/storage/normalize-row.test.node.d.ts +8 -0
  52. package/dist/modules/storage/normalize-row.test.node.js +89 -0
  53. package/dist/modules/storage/storage-commands.d.ts +443 -0
  54. package/dist/modules/storage/storage-commands.js +1263 -0
  55. package/dist/modules/storage/storage-insert.d.ts +21 -0
  56. package/dist/modules/storage/storage-insert.js +152 -0
  57. package/dist/modules/storage/storage-queries.d.ts +805 -0
  58. package/dist/modules/storage/storage-queries.js +1815 -0
  59. package/dist/modules/storage/storage-store-manifest.d.ts +77 -0
  60. package/dist/modules/storage/storage-store-manifest.js +168 -0
  61. package/dist/modules/storage/storage-utils.d.ts +49 -0
  62. package/dist/modules/storage/storage-utils.js +76 -0
  63. package/dist/modules/storage/tests/dialect-pins.integration.test.d.ts +8 -0
  64. package/dist/modules/storage/tests/dialect-pins.integration.test.js +266 -0
  65. package/dist/modules/storage/tests/storage-commands.test.d.ts +8 -0
  66. package/dist/modules/storage/tests/storage-commands.test.js +324 -0
  67. package/dist/modules/storage/tests/storage-document-paths.test.d.ts +8 -0
  68. package/dist/modules/storage/tests/storage-document-paths.test.js +214 -0
  69. package/dist/modules/storage/tests/storage-document-tree.test.d.ts +8 -0
  70. package/dist/modules/storage/tests/storage-document-tree.test.js +361 -0
  71. package/dist/modules/storage/tests/storage-queries.test.d.ts +8 -0
  72. package/dist/modules/storage/tests/storage-queries.test.js +685 -0
  73. package/dist/modules/storage/tests/storage-status-and-lifecycle.test.d.ts +8 -0
  74. package/dist/modules/storage/tests/storage-status-and-lifecycle.test.js +268 -0
  75. package/package.json +91 -0
@@ -0,0 +1,21 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ */
8
+ import { type FlattenedFieldValue } from '@byline/core';
9
+ import type { booleanStore, datetimeStore, fileStore, jsonStore, metaStore, numericStore, relationStore, textStore } from '../../database/schema/index.js';
10
+ type FieldInsertBuckets = {
11
+ text: (typeof textStore.$inferInsert)[];
12
+ numeric: (typeof numericStore.$inferInsert)[];
13
+ boolean: (typeof booleanStore.$inferInsert)[];
14
+ datetime: (typeof datetimeStore.$inferInsert)[];
15
+ file: (typeof fileStore.$inferInsert)[];
16
+ relation: (typeof relationStore.$inferInsert)[];
17
+ json: (typeof jsonStore.$inferInsert)[];
18
+ meta: (typeof metaStore.$inferInsert)[];
19
+ };
20
+ export declare const prepareFieldInsertBuckets: (flattenedFields: FlattenedFieldValue[], document_version_id: string, collection_id: string) => FieldInsertBuckets;
21
+ export {};
@@ -0,0 +1,152 @@
1
+ /**
2
+ * This Source Code is subject to the terms of the Mozilla Public
3
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
4
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5
+ *
6
+ * Copyright (c) Infonomic Company Limited
7
+ */
8
+ import { ERR_DATABASE, getLogger } from '@byline/core';
9
+ import { v7 as uuidv7 } from 'uuid';
10
+ export const prepareFieldInsertBuckets = (flattenedFields, document_version_id, collection_id) => {
11
+ const buckets = {
12
+ text: [],
13
+ numeric: [],
14
+ boolean: [],
15
+ datetime: [],
16
+ file: [],
17
+ relation: [],
18
+ json: [],
19
+ meta: [],
20
+ };
21
+ for (const field of flattenedFields) {
22
+ const { field_type, field_path, locale } = field;
23
+ if (field_type === 'meta') {
24
+ buckets.meta.push({
25
+ id: uuidv7(),
26
+ document_version_id,
27
+ collection_id,
28
+ type: field.type,
29
+ path: field_path.join('.'),
30
+ item_id: field.item_id,
31
+ });
32
+ continue;
33
+ }
34
+ const base = {
35
+ id: uuidv7(),
36
+ document_version_id,
37
+ collection_id,
38
+ field_path: field_path.join('.'),
39
+ field_name: field_path[field_path.length - 1] ?? '',
40
+ locale,
41
+ parent_path: field_path.length > 1 ? field_path.slice(0, -1).join('.') : undefined,
42
+ };
43
+ switch (field_type) {
44
+ case 'text':
45
+ buckets.text.push({ ...base, value: field.value });
46
+ continue;
47
+ case 'numeric':
48
+ buckets.numeric.push({
49
+ ...base,
50
+ number_type: field.number_type,
51
+ value_float: field.value_float,
52
+ value_integer: field.value_integer,
53
+ value_decimal: field.value_decimal,
54
+ });
55
+ continue;
56
+ case 'boolean':
57
+ buckets.boolean.push({
58
+ ...base,
59
+ value: field.value,
60
+ });
61
+ continue;
62
+ case 'datetime':
63
+ buckets.datetime.push({
64
+ ...base,
65
+ date_type: field.date_type,
66
+ // Real dialect divergence from pg, found via typecheck rather than
67
+ // assumed: `drizzle-orm/pg-core`'s `date()` defaults to *string*
68
+ // mode (`PgDateStringBuilder`) unless `{ mode: 'date' }` is passed;
69
+ // `drizzle-orm/mysql-core`'s `date()` defaults the other way — to
70
+ // *`Date`* mode (`MySqlDateBuilder`) unless `{ mode: 'string' }` is
71
+ // passed. The schema's `value_date: date('value_date')`
72
+ // (`src/database/schema/index.ts`, unchanged from Task 8/PR 1) is
73
+ // therefore `Date`-typed on insert here, the mirror image of pg's
74
+ // `toDateOnlyString` — so this coerces to `Date` instead of a
75
+ // 'YYYY-MM-DD' string. `mapToDriverValue` is identity (unverified
76
+ // by an override in the mysql-core source), so mysql2 receives the
77
+ // `Date` object directly and formats it per the pool's `timezone:
78
+ // 'Z'` option.
79
+ value_date: toDate(field.value_date),
80
+ value_time: field.value_time,
81
+ // `value_timestamp_tz` arrives as a `Date` from form widgets but
82
+ // as a string from `getAllFieldValues` — the UNION ALL declares
83
+ // the column as MySQL `DATETIME(6)` (no TZ; UTC by connection-level
84
+ // convention, see `src/index.ts`'s `timezone: 'Z'` pool option),
85
+ // and mysql2 maps a `datetime` column to a string on read.
86
+ // Drizzle's own `mapToDriverValue` for the (default, non-'string')
87
+ // `datetime()` builder calls `.toISOString()` unguarded on insert
88
+ // — confirmed against the drizzle-orm/mysql-core source — so we
89
+ // coerce here, exactly like pg's `toDate`.
90
+ value_timestamp_tz: toDate(field.value_timestamp_tz),
91
+ });
92
+ continue;
93
+ case 'file':
94
+ buckets.file.push({
95
+ ...base,
96
+ file_id: field.file_id,
97
+ filename: field.filename,
98
+ original_filename: field.original_filename,
99
+ mime_type: field.mime_type,
100
+ file_size: field.file_size,
101
+ storage_provider: field.storage_provider,
102
+ storage_path: field.storage_path,
103
+ storage_url: field.storage_url,
104
+ file_hash: field.file_hash,
105
+ image_width: field.image_width,
106
+ image_height: field.image_height,
107
+ image_format: field.image_format,
108
+ processing_status: field.processing_status || 'pending', // TODO: Is 'pending' the appropriate default status?
109
+ thumbnail_generated: field.thumbnail_generated || false,
110
+ variants: field.variants,
111
+ });
112
+ continue;
113
+ case 'relation':
114
+ buckets.relation.push({
115
+ ...base,
116
+ target_document_id: field.target_document_id,
117
+ target_collection_id: field.target_collection_id,
118
+ relationship_type: field.relationship_type || 'reference', // TODO: Is this the appropriate place to set this?
119
+ cascade_delete: field.cascade_delete || false, // TODO: Same question?
120
+ });
121
+ continue;
122
+ case 'json':
123
+ buckets.json.push({
124
+ ...base,
125
+ value: field.value,
126
+ });
127
+ continue;
128
+ default:
129
+ throw ERR_DATABASE({
130
+ message: `unexpected field type: ${field_type}`,
131
+ details: { fieldType: field_type },
132
+ }).log(getLogger());
133
+ }
134
+ }
135
+ return buckets;
136
+ };
137
+ /**
138
+ * Coerce a date/timestamp field value to a `Date` instance — both the
139
+ * MySQL `date` and (default-mode) `datetime` column builders require one on
140
+ * insert, per the dialect-divergence notes above. Accepts:
141
+ * - `Date` → passed through
142
+ * - string → parsed via `new Date(...)` (ISO, MySQL `date`, or MySQL
143
+ * `datetime` shape — all parse correctly through the `Date` constructor)
144
+ * - null / undefined → undefined (no insert)
145
+ */
146
+ function toDate(value) {
147
+ if (value == null)
148
+ return undefined;
149
+ if (value instanceof Date)
150
+ return value;
151
+ return new Date(value);
152
+ }