@vida-global/core 2.0.7 → 2.0.9
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/lib/activeRecord/db/migrator.js +2 -1
- package/lib/activeRecord/db/schema.js +10 -0
- package/lib/server/controllerMixins/renderer.js +4 -2
- package/package.json +1 -1
- package/test/activeRecord/db/migrator.test.js +2 -1
- package/test/activeRecord/db/schema.test.js +26 -0
- package/test/activeRecord/helpers/queryInterface.js +1 -0
- package/test/server/serverController.test.js +3 -3
|
@@ -128,11 +128,12 @@ class Migrator {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
|
|
131
|
-
async addIndex(tableName, fields, { concurrently, unique, name, where }) {
|
|
131
|
+
async addIndex(tableName, fields, { concurrently, unique, name, using, where }) {
|
|
132
132
|
const options = {fields: fields};
|
|
133
133
|
if (concurrently) options.concurrently = true;
|
|
134
134
|
if (unique) options.unique = true;
|
|
135
135
|
if (name) options.name = name;
|
|
136
|
+
if (using) options.using = using;
|
|
136
137
|
if (where) options.where = where;
|
|
137
138
|
|
|
138
139
|
await this.#sequelizeQueryInterface.addIndex(tableName, options);
|
|
@@ -81,6 +81,7 @@ function cleanSchema(schema, dialect) {
|
|
|
81
81
|
const dataType = dataTypeForColumn(details, dialect);
|
|
82
82
|
if (dataType) details.type = dataType;
|
|
83
83
|
resolveAutoIncrementColumns(details);
|
|
84
|
+
resolveTimestampDefaults(details, dialect);
|
|
84
85
|
resolveUUIDColumns(details);
|
|
85
86
|
}
|
|
86
87
|
}
|
|
@@ -97,6 +98,15 @@ function resolveAutoIncrementColumns(details) {
|
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
|
|
101
|
+
function resolveTimestampDefaults(details, dialect) {
|
|
102
|
+
if (dialect != 'postgres') return;
|
|
103
|
+
if (details.type != Sequelize.DataTypes.DATE) return;
|
|
104
|
+
if (!/^(now\(\)|CURRENT_TIMESTAMP)$/i.test(details.defaultValue)) return;
|
|
105
|
+
|
|
106
|
+
details.defaultValue = Sequelize.NOW;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
100
110
|
function dataTypeForColumn(details, dialect) {
|
|
101
111
|
const typeStr = details.type.replace(/\(.*\)/, '').toUpperCase();
|
|
102
112
|
|
|
@@ -231,11 +231,13 @@ const InstanceMethods = {
|
|
|
231
231
|
if (!this._isStreaming) throw new NoActiveStreamError();
|
|
232
232
|
if (this._streamAbortController?.signal?.aborted || this.writableEnded) return;
|
|
233
233
|
|
|
234
|
+
let msg;
|
|
234
235
|
if (evt) {
|
|
235
|
-
|
|
236
|
+
msg = `event: ${evt}\ndata: ${data}\n\n`;
|
|
237
|
+
} else {
|
|
238
|
+
msg = `data: ${data}\n\n`;
|
|
236
239
|
}
|
|
237
240
|
|
|
238
|
-
const msg = `data: ${data}\n\n`;
|
|
239
241
|
this._response.write(msg);
|
|
240
242
|
}
|
|
241
243
|
}
|
package/package.json
CHANGED
|
@@ -102,7 +102,7 @@ describe('Migrator', () => {
|
|
|
102
102
|
|
|
103
103
|
describe('Migrator#addIndex', () => {
|
|
104
104
|
it.each([
|
|
105
|
-
['all supported options', { concurrently: true, unique: true, where: {}, name: 'foo' }],
|
|
105
|
+
['all supported options', { concurrently: true, unique: true, where: {}, name: 'foo', using: 'gin' }],
|
|
106
106
|
['empty options', {}],
|
|
107
107
|
['falsey options', { concurrently: false, unique: false, where: null, name: null }],
|
|
108
108
|
])('builds addIndex options for %s', async (_label, options) => {
|
|
@@ -114,6 +114,7 @@ describe('Migrator', () => {
|
|
|
114
114
|
if (options.unique) expectedOptions.unique = true;
|
|
115
115
|
if (options.where) expectedOptions.where = options.where;
|
|
116
116
|
if (options.name) expectedOptions.name = options.name;
|
|
117
|
+
if (options.using) expectedOptions.using = options.using;
|
|
117
118
|
|
|
118
119
|
await Helpers.migrator.addIndex(tableName, fields, options);
|
|
119
120
|
|
|
@@ -154,6 +154,32 @@ describe('activeRecord/db/schema', () => {
|
|
|
154
154
|
expect(schema.id.defaultValue).toBeUndefined();
|
|
155
155
|
});
|
|
156
156
|
});
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
describe('timestamp default resolution', () => {
|
|
160
|
+
it.each(['now()', 'CURRENT_TIMESTAMP'])(
|
|
161
|
+
'maps PostgreSQL %s defaults to Sequelize.NOW',
|
|
162
|
+
(defaultValue) => {
|
|
163
|
+
importSchema.mockImplementation(() => ({
|
|
164
|
+
created_at: { type: 'TIMESTAMP WITH TIME ZONE', defaultValue }
|
|
165
|
+
}));
|
|
166
|
+
|
|
167
|
+
const schema = getActiveRecordSchema('t', 'main', 'postgres');
|
|
168
|
+
|
|
169
|
+
expect(schema.created_at.defaultValue).toBe(Sequelize.NOW);
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
it ('does not rewrite SQLite timestamp defaults', () => {
|
|
174
|
+
importSchema.mockImplementation(() => ({
|
|
175
|
+
created_at: { type: 'DATETIME', defaultValue: 'CURRENT_TIMESTAMP' }
|
|
176
|
+
}));
|
|
177
|
+
|
|
178
|
+
const schema = getActiveRecordSchema('t', 'main', 'sqlite');
|
|
179
|
+
|
|
180
|
+
expect(schema.created_at.defaultValue).toBe('CURRENT_TIMESTAMP');
|
|
181
|
+
});
|
|
182
|
+
});
|
|
157
183
|
});
|
|
158
184
|
|
|
159
185
|
|
|
@@ -1786,12 +1786,12 @@ describe('VidaServerController', () => {
|
|
|
1786
1786
|
.toThrow(NoActiveStreamError);
|
|
1787
1787
|
});
|
|
1788
1788
|
|
|
1789
|
-
it ('writes
|
|
1789
|
+
it ('writes the event and data lines as a single atomic frame when an event name is provided', async () => {
|
|
1790
1790
|
await controller.streamSseResponse(async () => {
|
|
1791
1791
|
response.write.mockClear();
|
|
1792
1792
|
controller.writeStreamEvent('progress', 'halfway');
|
|
1793
|
-
expect(response.write).
|
|
1794
|
-
expect(response.write).
|
|
1793
|
+
expect(response.write).toHaveBeenCalledTimes(1);
|
|
1794
|
+
expect(response.write).toHaveBeenCalledWith('event: progress\ndata: halfway\n\n');
|
|
1795
1795
|
}, jest.fn());
|
|
1796
1796
|
});
|
|
1797
1797
|
|