@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.
- package/LICENSE +373 -0
- package/README.md +283 -0
- package/dist/database/schema/auth.d.ts +951 -0
- package/dist/database/schema/auth.js +226 -0
- package/dist/database/schema/common.d.ts +168 -0
- package/dist/database/schema/common.js +130 -0
- package/dist/database/schema/index.d.ts +3419 -0
- package/dist/database/schema/index.js +895 -0
- package/dist/database/schema/schema-pins.test.node.d.ts +52 -0
- package/dist/database/schema/schema-pins.test.node.js +398 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.js +151 -0
- package/dist/lib/boot-check.d.ts +22 -0
- package/dist/lib/boot-check.js +42 -0
- package/dist/lib/boot-check.test.node.d.ts +8 -0
- package/dist/lib/boot-check.test.node.js +46 -0
- package/dist/lib/db-manager.d.ts +54 -0
- package/dist/lib/db-manager.js +49 -0
- package/dist/lib/test-db.d.ts +37 -0
- package/dist/lib/test-db.js +111 -0
- package/dist/lib/test-helper.d.ts +33 -0
- package/dist/lib/test-helper.js +68 -0
- package/dist/modules/admin/admin-permissions-repository.d.ts +35 -0
- package/dist/modules/admin/admin-permissions-repository.js +101 -0
- package/dist/modules/admin/admin-preferences-repository.d.ts +62 -0
- package/dist/modules/admin/admin-preferences-repository.js +156 -0
- package/dist/modules/admin/admin-roles-repository.d.ts +11 -0
- package/dist/modules/admin/admin-roles-repository.js +209 -0
- package/dist/modules/admin/admin-store.d.ts +20 -0
- package/dist/modules/admin/admin-store.js +30 -0
- package/dist/modules/admin/admin-users-repository.d.ts +11 -0
- package/dist/modules/admin/admin-users-repository.js +303 -0
- package/dist/modules/admin/index.d.ts +27 -0
- package/dist/modules/admin/index.js +27 -0
- package/dist/modules/admin/refresh-tokens-repository.d.ts +34 -0
- package/dist/modules/admin/refresh-tokens-repository.js +160 -0
- package/dist/modules/audit/audit-commands.d.ts +29 -0
- package/dist/modules/audit/audit-commands.js +40 -0
- package/dist/modules/audit/audit-queries.d.ts +41 -0
- package/dist/modules/audit/audit-queries.js +169 -0
- package/dist/modules/counters/counters-commands.d.ts +54 -0
- package/dist/modules/counters/counters-commands.js +121 -0
- package/dist/modules/counters/tests/counters-concurrency.test.d.ts +8 -0
- package/dist/modules/counters/tests/counters-concurrency.test.js +111 -0
- package/dist/modules/storage/classify-error.d.ts +34 -0
- package/dist/modules/storage/classify-error.js +50 -0
- package/dist/modules/storage/classify-error.test.node.d.ts +8 -0
- package/dist/modules/storage/classify-error.test.node.js +89 -0
- package/dist/modules/storage/normalize-row.d.ts +55 -0
- package/dist/modules/storage/normalize-row.js +135 -0
- package/dist/modules/storage/normalize-row.test.node.d.ts +8 -0
- package/dist/modules/storage/normalize-row.test.node.js +89 -0
- package/dist/modules/storage/storage-commands.d.ts +443 -0
- package/dist/modules/storage/storage-commands.js +1263 -0
- package/dist/modules/storage/storage-insert.d.ts +21 -0
- package/dist/modules/storage/storage-insert.js +152 -0
- package/dist/modules/storage/storage-queries.d.ts +805 -0
- package/dist/modules/storage/storage-queries.js +1815 -0
- package/dist/modules/storage/storage-store-manifest.d.ts +77 -0
- package/dist/modules/storage/storage-store-manifest.js +168 -0
- package/dist/modules/storage/storage-utils.d.ts +49 -0
- package/dist/modules/storage/storage-utils.js +76 -0
- package/dist/modules/storage/tests/dialect-pins.integration.test.d.ts +8 -0
- package/dist/modules/storage/tests/dialect-pins.integration.test.js +266 -0
- package/dist/modules/storage/tests/storage-commands.test.d.ts +8 -0
- package/dist/modules/storage/tests/storage-commands.test.js +324 -0
- package/dist/modules/storage/tests/storage-document-paths.test.d.ts +8 -0
- package/dist/modules/storage/tests/storage-document-paths.test.js +214 -0
- package/dist/modules/storage/tests/storage-document-tree.test.d.ts +8 -0
- package/dist/modules/storage/tests/storage-document-tree.test.js +361 -0
- package/dist/modules/storage/tests/storage-queries.test.d.ts +8 -0
- package/dist/modules/storage/tests/storage-queries.test.js +685 -0
- package/dist/modules/storage/tests/storage-status-and-lifecycle.test.d.ts +8 -0
- package/dist/modules/storage/tests/storage-status-and-lifecycle.test.js +268 -0
- 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
|
+
}
|