@objectstack/driver-sql 10.2.0 → 11.0.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 +202 -93
- package/dist/index.d.mts +83 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.js +199 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +199 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -3
package/LICENSE
CHANGED
|
@@ -1,93 +1,202 @@
|
|
|
1
|
-
License
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
Licensor
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute
|
|
108
|
+
must include a readable copy of the attribution notices
|
|
109
|
+
contained within such NOTICE file, excluding those notices
|
|
110
|
+
that do not pertain to any part of the Derivative Works,
|
|
111
|
+
in at least one of the following places: within a NOTICE
|
|
112
|
+
text file distributed as part of the Derivative Works; within
|
|
113
|
+
the Source form or documentation, if provided along with
|
|
114
|
+
the Derivative Works; or, within a display generated by the
|
|
115
|
+
Derivative Works, if and wherever such third-party notices
|
|
116
|
+
normally appear. The contents of the NOTICE file are for
|
|
117
|
+
informational purposes only and do not modify the License.
|
|
118
|
+
You may add Your own attribution notices within Derivative
|
|
119
|
+
Works that You distribute, alongside or as an addendum to
|
|
120
|
+
the NOTICE text from the Work, provided that such additional
|
|
121
|
+
attribution notices cannot be construed as modifying the
|
|
122
|
+
License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 ObjectStack
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/dist/index.d.mts
CHANGED
|
@@ -217,6 +217,7 @@ declare class SqlDriver implements IDataDriver {
|
|
|
217
217
|
protected numericFields: Record<string, string[]>;
|
|
218
218
|
protected dateFields: Record<string, Set<string>>;
|
|
219
219
|
protected datetimeFields: Record<string, Set<string>>;
|
|
220
|
+
protected timeFields: Record<string, Set<string>>;
|
|
220
221
|
/**
|
|
221
222
|
* Federation read path (ADR-0015). For external objects whose physical
|
|
222
223
|
* remote table differs from the object name, these map between the two so
|
|
@@ -425,6 +426,26 @@ declare class SqlDriver implements IDataDriver {
|
|
|
425
426
|
* tenant scopes it for isolation.
|
|
426
427
|
*/
|
|
427
428
|
protected fillAutoNumberFields(object: string, row: Record<string, any>, options?: DriverOptions): Promise<void>;
|
|
429
|
+
/**
|
|
430
|
+
* Stamp the builtin audit timestamps to one canonical ISO-8601-with-`Z`
|
|
431
|
+
* instant on the SQLite write paths (`create`/`bulkCreate`/`upsert`), so
|
|
432
|
+
* INSERT and UPDATE agree on a single zone-explicit format.
|
|
433
|
+
*
|
|
434
|
+
* Without this, an insert that omits `created_at`/`updated_at` falls back to
|
|
435
|
+
* the column's `CURRENT_TIMESTAMP` default, which on SQLite renders a
|
|
436
|
+
* zone-NAIVE, space-separated `'YYYY-MM-DD HH:MM:SS'` (no millis, no zone) —
|
|
437
|
+
* the same ambiguity the old UPDATE stamp had. Stamping app-side (rather than
|
|
438
|
+
* changing the column default) fixes this for EXISTING tenant databases
|
|
439
|
+
* immediately, since their tables keep the legacy default. Legacy/raw rows
|
|
440
|
+
* still written zone-naive are repaired on read by
|
|
441
|
+
* `repairNaiveUtcAuditTimestamp`.
|
|
442
|
+
*
|
|
443
|
+
* Only fills a slot the caller left empty — an explicit value (a seed fixture,
|
|
444
|
+
* the sys_metadata writer, a service outbox) is preserved. No-op for
|
|
445
|
+
* timestamp-less objects and for Postgres/MySQL, whose native `now()` column
|
|
446
|
+
* default already stores a zone-aware TIMESTAMP.
|
|
447
|
+
*/
|
|
448
|
+
protected stampInsertTimestamps(object: string, formatted: Record<string, any>): void;
|
|
428
449
|
update(object: string, id: string | number, data: Record<string, any>, options?: DriverOptions): Promise<any>;
|
|
429
450
|
upsert(object: string, data: Record<string, any>, conflictKeys?: string[], options?: DriverOptions): Promise<Record<string, any>>;
|
|
430
451
|
delete(object: string, id: string | number, options?: DriverOptions): Promise<boolean>;
|
|
@@ -476,6 +497,30 @@ declare class SqlDriver implements IDataDriver {
|
|
|
476
497
|
analyzeQuery(object: string, query: any, options?: DriverOptions): Promise<any>;
|
|
477
498
|
syncSchema(object: string, schema: unknown, _options?: DriverOptions): Promise<void>;
|
|
478
499
|
dropTable(object: string, _options?: DriverOptions): Promise<void>;
|
|
500
|
+
/**
|
|
501
|
+
* Resolve the per-table tenant-isolation column for a schema, honoring an
|
|
502
|
+
* explicit tenancy opt-out. Single source of truth for both {@link initObjects}
|
|
503
|
+
* and {@link registerExternalObject} (they previously inlined this logic and
|
|
504
|
+
* drifted).
|
|
505
|
+
*
|
|
506
|
+
* Precedence:
|
|
507
|
+
* 1. `tenancy.enabled === false` → `null` (NO driver-level org scope), even
|
|
508
|
+
* when the object carries an `organization_id` column. Platform-global
|
|
509
|
+
* objects (e.g. `sys_license`) keep an optional, often-NULL org FK but must
|
|
510
|
+
* NOT be tenant-scoped: otherwise an authenticated caller's active-org
|
|
511
|
+
* `DriverOptions.tenantId` injects `WHERE organization_id = <org>` and every
|
|
512
|
+
* NULL-org / cross-org row silently disappears (the platform admin then
|
|
513
|
+
* reads zero licenses while an unscoped/anonymous read still sees them).
|
|
514
|
+
* The declarative branch below already respected `enabled !== false`; the
|
|
515
|
+
* implicit `organization_id` fallback did not — this closes that gap.
|
|
516
|
+
* 2. Declared `tenancy.tenantField` (when that field exists on the object).
|
|
517
|
+
* 3. Implicit `organization_id` column detection (legacy objects whose
|
|
518
|
+
* multi-tenant column was injected by the kernel without a spec migration).
|
|
519
|
+
*/
|
|
520
|
+
protected computeTenantField(schema: {
|
|
521
|
+
fields?: Record<string, any>;
|
|
522
|
+
tenancy?: any;
|
|
523
|
+
}): string | null;
|
|
479
524
|
/**
|
|
480
525
|
* Batch-initialise tables from an array of object definitions.
|
|
481
526
|
*/
|
|
@@ -683,6 +728,20 @@ declare class SqlDriver implements IDataDriver {
|
|
|
683
728
|
* read (`formatOutput`) paths so all three agree on what a date *is*.
|
|
684
729
|
*/
|
|
685
730
|
protected toDateOnly(value: any): any;
|
|
731
|
+
/**
|
|
732
|
+
* Read-side repair for a `Field.time` value to its wall-clock time-of-day
|
|
733
|
+
* (`Field.time` is a tz-naive time-of-day, not an instant — #2004). This is a
|
|
734
|
+
* deliberately NARROW, read-only normalization (no write/filter counterpart):
|
|
735
|
+
* it only strips a leading `YYYY-MM-DD` date — exactly what a legacy
|
|
736
|
+
* `defaultValue: 'NOW()'` column took when the default was still the full
|
|
737
|
+
* `CURRENT_TIMESTAMP` (or a full ISO datetime that leaked into the column) —
|
|
738
|
+
* and any trailing zone, leaving the time portion. A value that is ALREADY a
|
|
739
|
+
* bare time-of-day (`HH:MM[:SS[.fff]]`, with or without `Z`/offset) is returned
|
|
740
|
+
* untouched, so the common case never changes and no write/read asymmetry is
|
|
741
|
+
* introduced. A `Date`/epoch-ms (defensive — a Date bound to a time column)
|
|
742
|
+
* maps to its UTC time-of-day. `null`/unrecognised shapes pass through.
|
|
743
|
+
*/
|
|
744
|
+
protected toTimeOnly(value: any): any;
|
|
686
745
|
/**
|
|
687
746
|
* Normalise a filter value for a single column so the comparison the
|
|
688
747
|
* driver sends to SQLite matches the on-disk representation.
|
|
@@ -747,6 +806,30 @@ declare class SqlDriver implements IDataDriver {
|
|
|
747
806
|
protected applyWriteColumnMap(object: string, data: any): any;
|
|
748
807
|
protected mapAggregateFunc(func: string): string;
|
|
749
808
|
protected buildWindowFunction(spec: any): string;
|
|
809
|
+
/**
|
|
810
|
+
* The driver-native column DEFAULT for a `defaultValue: 'NOW()'` field.
|
|
811
|
+
*
|
|
812
|
+
* Postgres/MySQL use native `now()` — a real zone-aware TIMESTAMP that never
|
|
813
|
+
* had the ambiguity below. SQLite has no timestamp type and `knex.fn.now()`
|
|
814
|
+
* compiles to `CURRENT_TIMESTAMP`, which renders a timezone-NAIVE,
|
|
815
|
+
* space-separated `'YYYY-MM-DD HH:MM:SS'` (no millis, no zone). `Date.parse`
|
|
816
|
+
* reads such a zone-less string as LOCAL time, so a stored UTC wall-clock
|
|
817
|
+
* shifts by the host offset on a non-UTC runtime — the same class of bug
|
|
818
|
+
* ADR-0074 fixed for the builtin audit columns. Emit a canonical instead:
|
|
819
|
+
* - datetime → ISO-8601 with explicit `Z` (`2026-06-26T10:34:13.891Z`),
|
|
820
|
+
* matching `new Date().toISOString()` and the value
|
|
821
|
+
* `formatInput`'s `NOW()` safety-net writes;
|
|
822
|
+
* - date → `YYYY-MM-DD` UTC calendar day (matches `toDateOnly`, so the
|
|
823
|
+
* stored default already equals what an explicit write stores);
|
|
824
|
+
* - time → `HH:MM:SS.fff` UTC time-of-day (not a full timestamp).
|
|
825
|
+
*
|
|
826
|
+
* NOTE: a DDL default only governs NEWLY-created columns. An existing column
|
|
827
|
+
* keeps its legacy `CURRENT_TIMESTAMP` default and still emits naive text on a
|
|
828
|
+
* defaulted insert; `formatOutput` repairs those to canonical on read
|
|
829
|
+
* (`normalizeSqliteDatetimeOutput` for datetime, `toDateOnly` for date), so
|
|
830
|
+
* reads are uniform without a schema migration.
|
|
831
|
+
*/
|
|
832
|
+
protected nowColumnDefault(type: string): Knex.Raw;
|
|
750
833
|
protected createColumn(table: Knex.CreateTableBuilder, name: string, field: any): void;
|
|
751
834
|
protected ensureDatabaseExists(): Promise<void>;
|
|
752
835
|
protected createDatabase(): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -217,6 +217,7 @@ declare class SqlDriver implements IDataDriver {
|
|
|
217
217
|
protected numericFields: Record<string, string[]>;
|
|
218
218
|
protected dateFields: Record<string, Set<string>>;
|
|
219
219
|
protected datetimeFields: Record<string, Set<string>>;
|
|
220
|
+
protected timeFields: Record<string, Set<string>>;
|
|
220
221
|
/**
|
|
221
222
|
* Federation read path (ADR-0015). For external objects whose physical
|
|
222
223
|
* remote table differs from the object name, these map between the two so
|
|
@@ -425,6 +426,26 @@ declare class SqlDriver implements IDataDriver {
|
|
|
425
426
|
* tenant scopes it for isolation.
|
|
426
427
|
*/
|
|
427
428
|
protected fillAutoNumberFields(object: string, row: Record<string, any>, options?: DriverOptions): Promise<void>;
|
|
429
|
+
/**
|
|
430
|
+
* Stamp the builtin audit timestamps to one canonical ISO-8601-with-`Z`
|
|
431
|
+
* instant on the SQLite write paths (`create`/`bulkCreate`/`upsert`), so
|
|
432
|
+
* INSERT and UPDATE agree on a single zone-explicit format.
|
|
433
|
+
*
|
|
434
|
+
* Without this, an insert that omits `created_at`/`updated_at` falls back to
|
|
435
|
+
* the column's `CURRENT_TIMESTAMP` default, which on SQLite renders a
|
|
436
|
+
* zone-NAIVE, space-separated `'YYYY-MM-DD HH:MM:SS'` (no millis, no zone) —
|
|
437
|
+
* the same ambiguity the old UPDATE stamp had. Stamping app-side (rather than
|
|
438
|
+
* changing the column default) fixes this for EXISTING tenant databases
|
|
439
|
+
* immediately, since their tables keep the legacy default. Legacy/raw rows
|
|
440
|
+
* still written zone-naive are repaired on read by
|
|
441
|
+
* `repairNaiveUtcAuditTimestamp`.
|
|
442
|
+
*
|
|
443
|
+
* Only fills a slot the caller left empty — an explicit value (a seed fixture,
|
|
444
|
+
* the sys_metadata writer, a service outbox) is preserved. No-op for
|
|
445
|
+
* timestamp-less objects and for Postgres/MySQL, whose native `now()` column
|
|
446
|
+
* default already stores a zone-aware TIMESTAMP.
|
|
447
|
+
*/
|
|
448
|
+
protected stampInsertTimestamps(object: string, formatted: Record<string, any>): void;
|
|
428
449
|
update(object: string, id: string | number, data: Record<string, any>, options?: DriverOptions): Promise<any>;
|
|
429
450
|
upsert(object: string, data: Record<string, any>, conflictKeys?: string[], options?: DriverOptions): Promise<Record<string, any>>;
|
|
430
451
|
delete(object: string, id: string | number, options?: DriverOptions): Promise<boolean>;
|
|
@@ -476,6 +497,30 @@ declare class SqlDriver implements IDataDriver {
|
|
|
476
497
|
analyzeQuery(object: string, query: any, options?: DriverOptions): Promise<any>;
|
|
477
498
|
syncSchema(object: string, schema: unknown, _options?: DriverOptions): Promise<void>;
|
|
478
499
|
dropTable(object: string, _options?: DriverOptions): Promise<void>;
|
|
500
|
+
/**
|
|
501
|
+
* Resolve the per-table tenant-isolation column for a schema, honoring an
|
|
502
|
+
* explicit tenancy opt-out. Single source of truth for both {@link initObjects}
|
|
503
|
+
* and {@link registerExternalObject} (they previously inlined this logic and
|
|
504
|
+
* drifted).
|
|
505
|
+
*
|
|
506
|
+
* Precedence:
|
|
507
|
+
* 1. `tenancy.enabled === false` → `null` (NO driver-level org scope), even
|
|
508
|
+
* when the object carries an `organization_id` column. Platform-global
|
|
509
|
+
* objects (e.g. `sys_license`) keep an optional, often-NULL org FK but must
|
|
510
|
+
* NOT be tenant-scoped: otherwise an authenticated caller's active-org
|
|
511
|
+
* `DriverOptions.tenantId` injects `WHERE organization_id = <org>` and every
|
|
512
|
+
* NULL-org / cross-org row silently disappears (the platform admin then
|
|
513
|
+
* reads zero licenses while an unscoped/anonymous read still sees them).
|
|
514
|
+
* The declarative branch below already respected `enabled !== false`; the
|
|
515
|
+
* implicit `organization_id` fallback did not — this closes that gap.
|
|
516
|
+
* 2. Declared `tenancy.tenantField` (when that field exists on the object).
|
|
517
|
+
* 3. Implicit `organization_id` column detection (legacy objects whose
|
|
518
|
+
* multi-tenant column was injected by the kernel without a spec migration).
|
|
519
|
+
*/
|
|
520
|
+
protected computeTenantField(schema: {
|
|
521
|
+
fields?: Record<string, any>;
|
|
522
|
+
tenancy?: any;
|
|
523
|
+
}): string | null;
|
|
479
524
|
/**
|
|
480
525
|
* Batch-initialise tables from an array of object definitions.
|
|
481
526
|
*/
|
|
@@ -683,6 +728,20 @@ declare class SqlDriver implements IDataDriver {
|
|
|
683
728
|
* read (`formatOutput`) paths so all three agree on what a date *is*.
|
|
684
729
|
*/
|
|
685
730
|
protected toDateOnly(value: any): any;
|
|
731
|
+
/**
|
|
732
|
+
* Read-side repair for a `Field.time` value to its wall-clock time-of-day
|
|
733
|
+
* (`Field.time` is a tz-naive time-of-day, not an instant — #2004). This is a
|
|
734
|
+
* deliberately NARROW, read-only normalization (no write/filter counterpart):
|
|
735
|
+
* it only strips a leading `YYYY-MM-DD` date — exactly what a legacy
|
|
736
|
+
* `defaultValue: 'NOW()'` column took when the default was still the full
|
|
737
|
+
* `CURRENT_TIMESTAMP` (or a full ISO datetime that leaked into the column) —
|
|
738
|
+
* and any trailing zone, leaving the time portion. A value that is ALREADY a
|
|
739
|
+
* bare time-of-day (`HH:MM[:SS[.fff]]`, with or without `Z`/offset) is returned
|
|
740
|
+
* untouched, so the common case never changes and no write/read asymmetry is
|
|
741
|
+
* introduced. A `Date`/epoch-ms (defensive — a Date bound to a time column)
|
|
742
|
+
* maps to its UTC time-of-day. `null`/unrecognised shapes pass through.
|
|
743
|
+
*/
|
|
744
|
+
protected toTimeOnly(value: any): any;
|
|
686
745
|
/**
|
|
687
746
|
* Normalise a filter value for a single column so the comparison the
|
|
688
747
|
* driver sends to SQLite matches the on-disk representation.
|
|
@@ -747,6 +806,30 @@ declare class SqlDriver implements IDataDriver {
|
|
|
747
806
|
protected applyWriteColumnMap(object: string, data: any): any;
|
|
748
807
|
protected mapAggregateFunc(func: string): string;
|
|
749
808
|
protected buildWindowFunction(spec: any): string;
|
|
809
|
+
/**
|
|
810
|
+
* The driver-native column DEFAULT for a `defaultValue: 'NOW()'` field.
|
|
811
|
+
*
|
|
812
|
+
* Postgres/MySQL use native `now()` — a real zone-aware TIMESTAMP that never
|
|
813
|
+
* had the ambiguity below. SQLite has no timestamp type and `knex.fn.now()`
|
|
814
|
+
* compiles to `CURRENT_TIMESTAMP`, which renders a timezone-NAIVE,
|
|
815
|
+
* space-separated `'YYYY-MM-DD HH:MM:SS'` (no millis, no zone). `Date.parse`
|
|
816
|
+
* reads such a zone-less string as LOCAL time, so a stored UTC wall-clock
|
|
817
|
+
* shifts by the host offset on a non-UTC runtime — the same class of bug
|
|
818
|
+
* ADR-0074 fixed for the builtin audit columns. Emit a canonical instead:
|
|
819
|
+
* - datetime → ISO-8601 with explicit `Z` (`2026-06-26T10:34:13.891Z`),
|
|
820
|
+
* matching `new Date().toISOString()` and the value
|
|
821
|
+
* `formatInput`'s `NOW()` safety-net writes;
|
|
822
|
+
* - date → `YYYY-MM-DD` UTC calendar day (matches `toDateOnly`, so the
|
|
823
|
+
* stored default already equals what an explicit write stores);
|
|
824
|
+
* - time → `HH:MM:SS.fff` UTC time-of-day (not a full timestamp).
|
|
825
|
+
*
|
|
826
|
+
* NOTE: a DDL default only governs NEWLY-created columns. An existing column
|
|
827
|
+
* keeps its legacy `CURRENT_TIMESTAMP` default and still emits naive text on a
|
|
828
|
+
* defaulted insert; `formatOutput` repairs those to canonical on read
|
|
829
|
+
* (`normalizeSqliteDatetimeOutput` for datetime, `toDateOnly` for date), so
|
|
830
|
+
* reads are uniform without a schema migration.
|
|
831
|
+
*/
|
|
832
|
+
protected nowColumnDefault(type: string): Knex.Raw;
|
|
750
833
|
protected createColumn(table: Knex.CreateTableBuilder, name: string, field: any): void;
|
|
751
834
|
protected ensureDatabaseExists(): Promise<void>;
|
|
752
835
|
protected createDatabase(): Promise<void>;
|