@axinom/mosaic-db-common 0.10.0 → 0.11.0-rc.11
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/bin/mosaic-db.js +3 -0
- package/dist/auth/authentication-subject.d.ts +13 -0
- package/dist/auth/authentication-subject.d.ts.map +1 -1
- package/dist/auth/authentication-subject.js +1 -0
- package/dist/auth/authentication-subject.js.map +1 -1
- package/dist/auth/helpers.d.ts +4 -4
- package/dist/auth/helpers.d.ts.map +1 -1
- package/dist/auth/helpers.js +4 -4
- package/dist/auth/helpers.js.map +1 -1
- package/dist/cli/commands/generate-vscode-sql-snippets.d.ts +14 -0
- package/dist/cli/commands/generate-vscode-sql-snippets.d.ts.map +1 -0
- package/dist/cli/commands/generate-vscode-sql-snippets.js +206 -0
- package/dist/cli/commands/generate-vscode-sql-snippets.js.map +1 -0
- package/dist/cli/commands/index.d.ts +2 -0
- package/dist/cli/commands/index.d.ts.map +1 -0
- package/dist/cli/commands/index.js +14 -0
- package/dist/cli/commands/index.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/messaging/messaging-counter.js +5 -5
- package/dist/messaging/messaging-counter.js.map +1 -1
- package/dist/migrations/create-sql-define-functions-migration.js +6 -6
- package/dist/migrations/create-sql-define-functions-migration.js.map +1 -1
- package/dist/migrations/utils.js +10 -10
- package/dist/migrations/utils.js.map +1 -1
- package/dist/zapatos/transaction-with-context.js +4 -4
- package/dist/zapatos/transaction-with-context.js.map +1 -1
- package/migrations/README.md +230 -0
- package/migrations/before-migration/002-error-functions.sql +19 -1
- package/migrations/before-migration/003-validation-functions.sql +267 -43
- package/migrations/before-migration/006-authorization.sql +82 -25
- package/migrations/define/define-functions.sql +469 -73
- package/migrations/define/define-multitenancy-functions.sql +109 -26
- package/migrations/snippets/custom.code-snippets +250 -0
- package/migrations/snippets/multitenancy-custom.code-snippets +122 -0
- package/package.json +8 -3
package/bin/mosaic-db.js
ADDED
|
@@ -27,4 +27,17 @@ export interface PgAuthenticatedConsumer {
|
|
|
27
27
|
name: string;
|
|
28
28
|
profileId: string;
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* This interface represents an authenticated consumer application.
|
|
32
|
+
* These will be tokens issued by the User Service.
|
|
33
|
+
*
|
|
34
|
+
* Having name and profileId is not mandatory for these tokens.
|
|
35
|
+
*/
|
|
36
|
+
export interface PgAuthenticatedConsumerApplication {
|
|
37
|
+
tenantId: string;
|
|
38
|
+
environmentId: string;
|
|
39
|
+
sub: string;
|
|
40
|
+
name: string;
|
|
41
|
+
[key: string]: any;
|
|
42
|
+
}
|
|
30
43
|
//# sourceMappingURL=authentication-subject.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication-subject.d.ts","sourceRoot":"","sources":["../../src/auth/authentication-subject.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"authentication-subject.d.ts","sourceRoot":"","sources":["../../src/auth/authentication-subject.ts"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,MAAM,WAAW,gCAAgC;IAC/C,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE;QACX,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;KACzB,CAAC;IACF,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,kCAAkC;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication-subject.js","sourceRoot":"","sources":["../../src/auth/authentication-subject.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"authentication-subject.js","sourceRoot":"","sources":["../../src/auth/authentication-subject.ts"],"names":[],"mappings":";AAAA,uDAAuD"}
|
package/dist/auth/helpers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Dict } from '../common';
|
|
2
|
-
import { PgAuthenticatedConsumer, PgAuthenticatedManagementSubject } from './authentication-subject';
|
|
2
|
+
import { PgAuthenticatedConsumer, PgAuthenticatedConsumerApplication, PgAuthenticatedManagementSubject } from './authentication-subject';
|
|
3
3
|
/**
|
|
4
4
|
* Builds a pg settings object for the currently authenticated management subject.
|
|
5
5
|
* Used for RLS authentication in both PostGraphile and zapatos.
|
|
@@ -34,11 +34,11 @@ export declare function buildAuthPgSettings(subject: PgAuthenticatedManagementSu
|
|
|
34
34
|
*/
|
|
35
35
|
export declare function buildAuthPgSettings(subject: PgAuthenticatedManagementSubject | undefined): Dict<string>;
|
|
36
36
|
/**
|
|
37
|
-
* Builds a pg settings object for the currently authenticated Consumer with a dedicated DB Role.
|
|
37
|
+
* Builds a pg settings object for the currently authenticated Consumer or Consumer Application with a dedicated DB Role.
|
|
38
38
|
* Used for End User RLS authentication in both PostGraphile and zapatos.
|
|
39
39
|
*
|
|
40
|
-
* @param subject - Currently Authenticated Consumer
|
|
40
|
+
* @param subject - Currently Authenticated Consumer or Consumer Application
|
|
41
41
|
* @param dbRole - The database role to switch to
|
|
42
42
|
*/
|
|
43
|
-
export declare function buildConsumerAuthPgSettings(subject: PgAuthenticatedConsumer | undefined, dbRole: string): Dict<string>;
|
|
43
|
+
export declare function buildConsumerAuthPgSettings(subject: PgAuthenticatedConsumer | PgAuthenticatedConsumerApplication | undefined, dbRole: string): Dict<string>;
|
|
44
44
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/auth/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAYjC,OAAO,EACL,uBAAuB,EACvB,gCAAgC,EACjC,MAAM,0BAA0B,CAAC;AAElC;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,gCAAgC,GAAG,SAAS,EACrD,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,IAAI,CAAC,MAAM,CAAC,CAAC;AAEhB;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,gCAAgC,GAAG,SAAS,EACrD,MAAM,EAAE,MAAM,GACb,IAAI,CAAC,MAAM,CAAC,CAAC;AAShB;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,gCAAgC,GAAG,SAAS,EACrD,SAAS,EAAE,MAAM,GAChB,IAAI,CAAC,MAAM,CAAC,CAAC;AAEhB;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,gCAAgC,GAAG,SAAS,GACpD,IAAI,CAAC,MAAM,CAAC,CAAC;AAmBhB;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/auth/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAYjC,OAAO,EACL,uBAAuB,EACvB,kCAAkC,EAClC,gCAAgC,EACjC,MAAM,0BAA0B,CAAC;AAElC;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,gCAAgC,GAAG,SAAS,EACrD,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,IAAI,CAAC,MAAM,CAAC,CAAC;AAEhB;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,gCAAgC,GAAG,SAAS,EACrD,MAAM,EAAE,MAAM,GACb,IAAI,CAAC,MAAM,CAAC,CAAC;AAShB;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,gCAAgC,GAAG,SAAS,EACrD,SAAS,EAAE,MAAM,GAChB,IAAI,CAAC,MAAM,CAAC,CAAC;AAEhB;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,gCAAgC,GAAG,SAAS,GACpD,IAAI,CAAC,MAAM,CAAC,CAAC;AAmBhB;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EACH,uBAAuB,GACvB,kCAAkC,GAClC,SAAS,EACb,MAAM,EAAE,MAAM,GACb,IAAI,CAAC,MAAM,CAAC,CASd"}
|
package/dist/auth/helpers.js
CHANGED
|
@@ -9,12 +9,12 @@ function buildPgSettings(...args) {
|
|
|
9
9
|
exports.buildPgSettings = buildPgSettings;
|
|
10
10
|
function buildAuthPgSettings(...args) {
|
|
11
11
|
var _a, _b, _c, _d, _e, _f;
|
|
12
|
-
const pgSettings = Object.assign(Object.assign({ [constants_1.MOSAIC_AUTH_SUBJECT_NAME]: (_b = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_AUTH_SUBJECT_NAME, [constants_1.MOSAIC_TENANT_ID]: (_d = (_c = args[0]) === null || _c === void 0 ? void 0 : _c.tenantId) !== null && _d !== void 0 ? _d : '', [constants_1.MOSAIC_ENVIRONMENT_ID]: (_f = (_e = args[0]) === null || _e === void 0 ? void 0 : _e.environmentId) !== null && _f !== void 0 ? _f : '' }, zapatos_1.optional(args[1], () => {
|
|
12
|
+
const pgSettings = Object.assign(Object.assign({ [constants_1.MOSAIC_AUTH_SUBJECT_NAME]: (_b = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : constants_1.DEFAULT_AUTH_SUBJECT_NAME, [constants_1.MOSAIC_TENANT_ID]: (_d = (_c = args[0]) === null || _c === void 0 ? void 0 : _c.tenantId) !== null && _d !== void 0 ? _d : '', [constants_1.MOSAIC_ENVIRONMENT_ID]: (_f = (_e = args[0]) === null || _e === void 0 ? void 0 : _e.environmentId) !== null && _f !== void 0 ? _f : '' }, (0, zapatos_1.optional)(args[1], () => {
|
|
13
13
|
var _a, _b, _c, _d;
|
|
14
14
|
return ({
|
|
15
15
|
[constants_1.MOSAIC_AUTH_TAGS]: (_d = (_c = (_b = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.tags) === null || _b === void 0 ? void 0 : _b.join) === null || _c === void 0 ? void 0 : _c.call(_b, ',')) !== null && _d !== void 0 ? _d : '',
|
|
16
16
|
});
|
|
17
|
-
})), zapatos_1.optional(args[1], (serviceId) => {
|
|
17
|
+
})), (0, zapatos_1.optional)(args[1], (serviceId) => {
|
|
18
18
|
var _a, _b, _c, _d, _e;
|
|
19
19
|
return ({
|
|
20
20
|
[constants_1.MOSAIC_AUTH_PERMISSIONS]: (_e = (_d = (_c = (_b = (_a = args[0]) === null || _a === void 0 ? void 0 : _a.permissions) === null || _b === void 0 ? void 0 : _b[serviceId]) === null || _c === void 0 ? void 0 : _c.join) === null || _d === void 0 ? void 0 : _d.call(_c, ',')) !== null && _e !== void 0 ? _e : '',
|
|
@@ -24,10 +24,10 @@ function buildAuthPgSettings(...args) {
|
|
|
24
24
|
}
|
|
25
25
|
exports.buildAuthPgSettings = buildAuthPgSettings;
|
|
26
26
|
/**
|
|
27
|
-
* Builds a pg settings object for the currently authenticated Consumer with a dedicated DB Role.
|
|
27
|
+
* Builds a pg settings object for the currently authenticated Consumer or Consumer Application with a dedicated DB Role.
|
|
28
28
|
* Used for End User RLS authentication in both PostGraphile and zapatos.
|
|
29
29
|
*
|
|
30
|
-
* @param subject - Currently Authenticated Consumer
|
|
30
|
+
* @param subject - Currently Authenticated Consumer or Consumer Application
|
|
31
31
|
* @param dbRole - The database role to switch to
|
|
32
32
|
*/
|
|
33
33
|
function buildConsumerAuthPgSettings(subject, dbRole) {
|
package/dist/auth/helpers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/auth/helpers.ts"],"names":[],"mappings":";;;AAEA,4CASsB;AACtB,wCAAsC;
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/auth/helpers.ts"],"names":[],"mappings":";;;AAEA,4CASsB;AACtB,wCAAsC;AAiCtC,SAAgB,eAAe,CAAC,GAAG,IAAW;IAC5C,uBACE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IACV,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EACxC;AACJ,CAAC;AALD,0CAKC;AAyBD,SAAgB,mBAAmB,CAAC,GAAG,IAAW;;IAChD,MAAM,UAAU,iCACd,CAAC,oCAAwB,CAAC,EAAE,MAAA,MAAA,IAAI,CAAC,CAAC,CAAC,0CAAE,IAAI,mCAAI,qCAAyB,EACtE,CAAC,4BAAgB,CAAC,EAAE,MAAA,MAAA,IAAI,CAAC,CAAC,CAAC,0CAAE,QAAQ,mCAAI,EAAE,EAC3C,CAAC,iCAAqB,CAAC,EAAE,MAAA,MAAA,IAAI,CAAC,CAAC,CAAC,0CAAE,aAAa,mCAAI,EAAE,IAClD,IAAA,kBAAQ,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE;;QAAC,OAAA,CAAC;YAC1B,CAAC,4BAAgB,CAAC,EAAE,MAAA,MAAA,MAAA,MAAA,IAAI,CAAC,CAAC,CAAC,0CAAE,IAAI,0CAAE,IAAI,mDAAG,GAAG,CAAC,mCAAI,EAAE;SACrD,CAAC,CAAA;KAAA,CAAC,GACA,IAAA,kBAAQ,EAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,EAAE,EAAE;;QAAC,OAAA,CAAC;YACnC,CAAC,mCAAuB,CAAC,EACvB,MAAA,MAAA,MAAA,MAAA,MAAA,IAAI,CAAC,CAAC,CAAC,0CAAE,WAAW,0CAAG,SAAS,CAAC,0CAAE,IAAI,mDAAG,GAAG,CAAC,mCAAI,EAAE;SACvD,CAAC,CAAA;KAAA,CAAC,CACJ,CAAC;IAEF,OAAO,UAAU,CAAC;AACpB,CAAC;AAfD,kDAeC;AAED;;;;;;GAMG;AACH,SAAgB,2BAA2B,CACzC,OAGa,EACb,MAAc;;IAEd,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,CAAC,oCAAwB,CAAC,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,mCAAI,qCAAyB;QACtE,CAAC,4BAAgB,CAAC,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,QAAQ,mCAAI,EAAE;QAC3C,CAAC,iCAAqB,CAAC,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,aAAa,mCAAI,EAAE;QACrD,CAAC,mCAAuB,CAAC,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,mCAAI,EAAE;QAC7C,CAAC,kCAAsB,CAAC,EAAE,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,SAAS,mCAAI,EAAE;KACnD,CAAC;AACJ,CAAC;AAfD,kEAeC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CommandModule } from 'yargs';
|
|
2
|
+
/**
|
|
3
|
+
* CLI command options object.
|
|
4
|
+
*/
|
|
5
|
+
interface GenerateSnippetsOptions {
|
|
6
|
+
includeMultitenancySnippets: boolean;
|
|
7
|
+
snippetsFileNameWithoutExtension: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Yargs command module definition for `generate-vscode-sql-snippets` CLI script.
|
|
11
|
+
*/
|
|
12
|
+
export declare const generateVscodeSqlSnippets: CommandModule<unknown, GenerateSnippetsOptions>;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=generate-vscode-sql-snippets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-vscode-sql-snippets.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/generate-vscode-sql-snippets.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC;;GAEG;AACH,UAAU,uBAAuB;IAC/B,2BAA2B,EAAE,OAAO,CAAC;IACrC,gCAAgC,EAAE,MAAM,CAAC;CAC1C;AAqMD;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,aAAa,CACnD,OAAO,EACP,uBAAuB,CAsBxB,CAAC"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
3
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
4
|
+
var m = o[Symbol.asyncIterator], i;
|
|
5
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
6
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
7
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.generateVscodeSqlSnippets = void 0;
|
|
11
|
+
/* eslint-disable no-console */
|
|
12
|
+
const fs_1 = require("fs");
|
|
13
|
+
const path_1 = require("path");
|
|
14
|
+
const readdir = require("readdirp");
|
|
15
|
+
/**
|
|
16
|
+
* Colors the CLI text in green.
|
|
17
|
+
*/
|
|
18
|
+
const green = (text) => `\u001b[32m${text}\u001b[39m`;
|
|
19
|
+
/**
|
|
20
|
+
* Colors the CLI text in red.
|
|
21
|
+
*/
|
|
22
|
+
const red = (text) => `\u001b[31m${text}\u001b[39m`;
|
|
23
|
+
/**
|
|
24
|
+
* Returns a readable timestamp in current locale time, e.g. `[2021-05-13 13:02:12.685]`
|
|
25
|
+
*/
|
|
26
|
+
const getTimestamp = () => {
|
|
27
|
+
const offset = new Date().getTimezoneOffset() * 60000; //offset in milliseconds
|
|
28
|
+
const localISOTime = new Date(Date.now() - offset)
|
|
29
|
+
.toISOString()
|
|
30
|
+
.slice(0, -1)
|
|
31
|
+
.replace('T', ' ');
|
|
32
|
+
return `[${localISOTime}]`;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Writes generated snippets object to .vscode folder. Creates a folder if it does not exist.
|
|
36
|
+
* Returns a success message.
|
|
37
|
+
*/
|
|
38
|
+
const writeSourceFile = (snippetsFileName, contents) => {
|
|
39
|
+
const outDir = (0, path_1.join)(process.env.PROJECT_CWD || process.cwd(), '.vscode');
|
|
40
|
+
if (!(0, fs_1.existsSync)(outDir)) {
|
|
41
|
+
(0, fs_1.mkdirSync)(outDir, { recursive: true });
|
|
42
|
+
}
|
|
43
|
+
const filePath = (0, path_1.join)(outDir, `${snippetsFileName}.code-snippets`);
|
|
44
|
+
(0, fs_1.writeFileSync)(filePath, JSON.stringify(contents, null, 2), 'utf-8');
|
|
45
|
+
return `Success! Snippets file path: ${filePath}`;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Counter for potential unnamed snippets to generate temporary unique names.
|
|
49
|
+
*/
|
|
50
|
+
let unparsedSnippetIndex = 1;
|
|
51
|
+
/**
|
|
52
|
+
* Extracts snippet name and prefix from a line that defines a function.
|
|
53
|
+
* In case it's impossible to extract - placeholder values are used and logged (which is expected to be fixed).
|
|
54
|
+
* @example `CREATE OR REPLACE FUNCTION ax_utils.raise_error(` -> `{"prefix": "ax-raise-error", "snippetName": "Raise Error (Ax Utils)"}
|
|
55
|
+
*/
|
|
56
|
+
const parseFunctionName = (line, snippetJson) => {
|
|
57
|
+
var _a;
|
|
58
|
+
const match = (_a = new RegExp(/CREATE OR REPLACE FUNCTION (.*)\(/i).exec(line)) === null || _a === void 0 ? void 0 : _a[1];
|
|
59
|
+
let prefix = `unnamed-snippet-${unparsedSnippetIndex}`;
|
|
60
|
+
let snippetName = `Unnamed Snippet ${unparsedSnippetIndex}`;
|
|
61
|
+
if (!match) {
|
|
62
|
+
console.log(red(`Unable to parse the name for the following snippet. Naming the snippet ${prefix} instead.`));
|
|
63
|
+
console.log(snippetJson);
|
|
64
|
+
unparsedSnippetIndex++;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
prefix = match;
|
|
68
|
+
const [schemaName, functionName] = match.split('.');
|
|
69
|
+
const format = (text) => text
|
|
70
|
+
.replace(/_/g, ' ')
|
|
71
|
+
.replace(/(^\w{1})|(\s+\w{1})/g, (letter) => letter.toUpperCase());
|
|
72
|
+
snippetName = `${format(functionName)} (${format(schemaName)})`;
|
|
73
|
+
prefix = `ax-${functionName.replace(/_/g, '-')}`;
|
|
74
|
+
}
|
|
75
|
+
return { prefix, snippetName };
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Reads a file to memory as an array, where each element is a new line.
|
|
79
|
+
* Goes through the array and generates sql snippet objects based on file contents.
|
|
80
|
+
* Depends on comment conventions to work properly.
|
|
81
|
+
*/
|
|
82
|
+
const populateSnippets = async (filePath, snippetsObject) => {
|
|
83
|
+
const contents = (0, fs_1.readFileSync)(filePath, 'utf-8').split('\n').filter(Boolean);
|
|
84
|
+
const startTag = '/*-snippet';
|
|
85
|
+
const endTag = 'snippet-*/';
|
|
86
|
+
const funcLine = 'create or replace function';
|
|
87
|
+
let readingSnippet = false;
|
|
88
|
+
let snippetStringContents = '';
|
|
89
|
+
let snippetJson = undefined;
|
|
90
|
+
for (const line of contents) {
|
|
91
|
+
if (line.startsWith(startTag)) {
|
|
92
|
+
readingSnippet = true;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (line.startsWith(endTag)) {
|
|
96
|
+
snippetJson = JSON.parse(snippetStringContents);
|
|
97
|
+
snippetStringContents = '';
|
|
98
|
+
readingSnippet = false;
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (snippetJson && line.toLowerCase().startsWith(funcLine)) {
|
|
102
|
+
const { prefix, snippetName } = parseFunctionName(line, snippetJson);
|
|
103
|
+
snippetJson = Object.assign({ prefix }, snippetJson); // Adds a property to the first position
|
|
104
|
+
snippetJson['scope'] = 'sql';
|
|
105
|
+
snippetsObject[snippetName] = snippetJson;
|
|
106
|
+
snippetJson = undefined;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (readingSnippet) {
|
|
110
|
+
snippetStringContents += line;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return snippetsObject;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Reads all `.sql` files in `migrations` folder (and sub-folders), extracts snippet json objects from them, and returns a combined object with all snippets.
|
|
117
|
+
*/
|
|
118
|
+
const getParsedSnippets = async (dirPath, includeMultitenancySnippets) => {
|
|
119
|
+
var e_1, _a;
|
|
120
|
+
const parsedSnippets = {};
|
|
121
|
+
try {
|
|
122
|
+
for (var _b = __asyncValues(readdir(dirPath, {
|
|
123
|
+
fileFilter: '*.sql',
|
|
124
|
+
})), _c; _c = await _b.next(), !_c.done;) {
|
|
125
|
+
const { fullPath, path } = _c.value;
|
|
126
|
+
if (!includeMultitenancySnippets && path.includes('multitenancy')) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
console.log(getTimestamp(), `Parsing ${path}`);
|
|
130
|
+
await populateSnippets(fullPath, parsedSnippets);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
134
|
+
finally {
|
|
135
|
+
try {
|
|
136
|
+
if (_c && !_c.done && (_a = _b.return)) await _a.call(_b);
|
|
137
|
+
}
|
|
138
|
+
finally { if (e_1) throw e_1.error; }
|
|
139
|
+
}
|
|
140
|
+
return parsedSnippets;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Reads all `.code-snippets` files in `migrations` folder (and sub-folders) and returns a combined object with all snippets.
|
|
144
|
+
* These files contain custom snippets that are not tied to any one utils or define sql function.
|
|
145
|
+
*/
|
|
146
|
+
const getCustomSnippets = async (dirPath, includeMultitenancySnippets) => {
|
|
147
|
+
var e_2, _a;
|
|
148
|
+
let customSnippets = {};
|
|
149
|
+
try {
|
|
150
|
+
for (var _b = __asyncValues(readdir(dirPath, {
|
|
151
|
+
fileFilter: '*.code-snippets',
|
|
152
|
+
})), _c; _c = await _b.next(), !_c.done;) {
|
|
153
|
+
const { fullPath, path } = _c.value;
|
|
154
|
+
if (!includeMultitenancySnippets && path.includes('multitenancy')) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
console.log(getTimestamp(), `Reading ${path}`);
|
|
158
|
+
const fileContents = JSON.parse((0, fs_1.readFileSync)(fullPath, 'utf-8'));
|
|
159
|
+
customSnippets = Object.assign(Object.assign({}, customSnippets), fileContents);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
163
|
+
finally {
|
|
164
|
+
try {
|
|
165
|
+
if (_c && !_c.done && (_a = _b.return)) await _a.call(_b);
|
|
166
|
+
}
|
|
167
|
+
finally { if (e_2) throw e_2.error; }
|
|
168
|
+
}
|
|
169
|
+
return customSnippets;
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Iterates over all .sql files inside of the `migrations` folder.
|
|
173
|
+
* Parses each file based on comments and function definition conventions.
|
|
174
|
+
* Reads all .code-snippets files inside of the `migrations` folder and adds these snippets to parsed snippets.
|
|
175
|
+
* Generates or updates a VScode snippets file.
|
|
176
|
+
*/
|
|
177
|
+
const generate = async ({ includeMultitenancySnippets, snippetsFileNameWithoutExtension, }) => {
|
|
178
|
+
console.log(getTimestamp(), green(`Starting snippets generation!`));
|
|
179
|
+
const dirPath = (0, path_1.resolve)(__dirname, '../../../migrations');
|
|
180
|
+
const parsedSnippets = await getParsedSnippets(dirPath, includeMultitenancySnippets);
|
|
181
|
+
const customSnippets = await getCustomSnippets(dirPath, includeMultitenancySnippets);
|
|
182
|
+
const writeResult = writeSourceFile(snippetsFileNameWithoutExtension, Object.assign(Object.assign({}, parsedSnippets), customSnippets));
|
|
183
|
+
console.log(getTimestamp(), green(writeResult));
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Yargs command module definition for `generate-vscode-sql-snippets` CLI script.
|
|
187
|
+
*/
|
|
188
|
+
exports.generateVscodeSqlSnippets = {
|
|
189
|
+
command: 'generate-vscode-sql-snippets',
|
|
190
|
+
describe: 'Creates or updates a mosaic sql snippets file, providing an easier way to generate database migrations.',
|
|
191
|
+
builder: (yargs) => yargs
|
|
192
|
+
.option('includeMultitenancySnippets', {
|
|
193
|
+
alias: 'm',
|
|
194
|
+
describe: 'If set to true, would also include snippets for multitenancy define functions.',
|
|
195
|
+
default: false,
|
|
196
|
+
boolean: true,
|
|
197
|
+
})
|
|
198
|
+
.option('snippetsFileNameWithoutExtension', {
|
|
199
|
+
alias: 'f',
|
|
200
|
+
describe: 'Overrides default snippets file name with a custom value. Extension `code-snippets` will be attached to this value.',
|
|
201
|
+
default: 'mosaic-sql-migrations',
|
|
202
|
+
string: true,
|
|
203
|
+
}),
|
|
204
|
+
handler: generate,
|
|
205
|
+
};
|
|
206
|
+
//# sourceMappingURL=generate-vscode-sql-snippets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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":"","sources":["../../../src/cli/commands/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./generate-vscode-sql-snippets"), exports);
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/cli/commands/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iEAA+C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,GAAG,QAAO,IAOtB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.run = void 0;
|
|
4
|
+
const yargs = require("yargs");
|
|
5
|
+
const commands_1 = require("./commands");
|
|
6
|
+
const run = () => {
|
|
7
|
+
yargs
|
|
8
|
+
.scriptName('mosaic-db')
|
|
9
|
+
.command(commands_1.generateVscodeSqlSnippets)
|
|
10
|
+
.demandCommand()
|
|
11
|
+
.help()
|
|
12
|
+
.epilog(`For more information, visit https://portal.axinom.com.`).argv;
|
|
13
|
+
};
|
|
14
|
+
exports.run = run;
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,yCAAuD;AAEhD,MAAM,GAAG,GAAG,GAAS,EAAE;IAC5B,KAAK;SACF,UAAU,CAAC,WAAW,CAAC;SACvB,OAAO,CAAC,oCAAyB,CAAC;SAClC,aAAa,EAAE;SACf,IAAI,EAAE;SACN,MAAM,CAAC,wDAAwD,CAAC,CAAC,IAAI,CAAC;AAC3E,CAAC,CAAC;AAPW,QAAA,GAAG,OAOd"}
|
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.initMessagingCounter = exports.cleanupExpiredMessagingCounters = void 0;
|
|
4
4
|
const db_1 = require("zapatos/db");
|
|
5
5
|
const incrementAndGetCounter = async (key, ownerPool) => {
|
|
6
|
-
return db_1.transaction(ownerPool, db_1.IsolationLevel.Serializable, async (txnClient) => {
|
|
6
|
+
return (0, db_1.transaction)(ownerPool, db_1.IsolationLevel.Serializable, async (txnClient) => {
|
|
7
7
|
const counterKey = {
|
|
8
8
|
key: key,
|
|
9
9
|
};
|
|
10
|
-
const [{ counter }] = await db_1.sql `
|
|
10
|
+
const [{ counter }] = await (0, db_1.sql) `
|
|
11
11
|
INSERT INTO app_private.messaging_counter (key)
|
|
12
|
-
VALUES (${db_1.vals(counterKey)})
|
|
12
|
+
VALUES (${(0, db_1.vals)(counterKey)})
|
|
13
13
|
ON CONFLICT (key)
|
|
14
14
|
DO UPDATE
|
|
15
15
|
SET counter = app_private.messaging_counter.counter + 1,
|
|
@@ -25,14 +25,14 @@ const incrementAndGetCounter = async (key, ownerPool) => {
|
|
|
25
25
|
});
|
|
26
26
|
};
|
|
27
27
|
const deleteExpiredMessagingCounters = async (txnClient) => {
|
|
28
|
-
await db_1.sql `DELETE FROM app_private.messaging_counter WHERE expiration_date < current_timestamp`.run(txnClient);
|
|
28
|
+
await (0, db_1.sql) `DELETE FROM app_private.messaging_counter WHERE expiration_date < current_timestamp`.run(txnClient);
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
31
|
* This method can be called from a CRON job/task scheduler to regularly cleanup expired messages.
|
|
32
32
|
* @param ownerPool database pool with select and delete permissions to `app_private.messaging_counter`
|
|
33
33
|
*/
|
|
34
34
|
const cleanupExpiredMessagingCounters = async (ownerPool) => {
|
|
35
|
-
await db_1.transaction(ownerPool, db_1.IsolationLevel.Serializable, async (txnClient) => {
|
|
35
|
+
await (0, db_1.transaction)(ownerPool, db_1.IsolationLevel.Serializable, async (txnClient) => {
|
|
36
36
|
await deleteExpiredMessagingCounters(txnClient);
|
|
37
37
|
});
|
|
38
38
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messaging-counter.js","sourceRoot":"","sources":["../../src/messaging/messaging-counter.ts"],"names":[],"mappings":";;;AACA,mCAA+E;AAE/E,MAAM,sBAAsB,GAAG,KAAK,EAClC,GAAW,EACX,SAAe,EACE,EAAE;IACnB,OAAO,gBAAW,
|
|
1
|
+
{"version":3,"file":"messaging-counter.js","sourceRoot":"","sources":["../../src/messaging/messaging-counter.ts"],"names":[],"mappings":";;;AACA,mCAA+E;AAE/E,MAAM,sBAAsB,GAAG,KAAK,EAClC,GAAW,EACX,SAAe,EACE,EAAE;IACnB,OAAO,IAAA,gBAAW,EAChB,SAAS,EACT,mBAAc,CAAC,YAAY,EAC3B,KAAK,EAAE,SAAS,EAAE,EAAE;QAClB,MAAM,UAAU,GAAG;YACjB,GAAG,EAAE,GAAG;SACT,CAAC;QACF,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,MAAM,IAAA,QAAG,EAAA;;oBAEjB,IAAA,SAAI,EAAC,UAAU,CAAC;;;;;;OAM7B,CAAC,GAAG,CA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oBAAoB,wBAmB/B"}
|
|
@@ -4,7 +4,7 @@ exports.createSqlMultitenancyDefineFunctionsMigration = exports.createSqlDefineF
|
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const getPathToDefinitionsFolder = () => {
|
|
7
|
-
return path_1.resolve(__dirname, '..', '..', 'migrations', 'define');
|
|
7
|
+
return (0, path_1.resolve)(__dirname, '..', '..', 'migrations', 'define');
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* Reads the latest contents of the SQL functions to easily define tables, indexes, ...
|
|
@@ -15,9 +15,9 @@ const getPathToDefinitionsFolder = () => {
|
|
|
15
15
|
* @param postfixContent - content that should be added to the end. Useful for adding your own define functions.
|
|
16
16
|
*/
|
|
17
17
|
const createSqlDefineFunctionsMigration = async (migrationFolderPath, postfixContent = '') => {
|
|
18
|
-
const currentSqlFile = path_1.join(migrationFolderPath, 'current.sql');
|
|
18
|
+
const currentSqlFile = (0, path_1.join)(migrationFolderPath, 'current.sql');
|
|
19
19
|
let currentSql = '';
|
|
20
|
-
if (fs_1.existsSync(currentSqlFile)) {
|
|
20
|
+
if ((0, fs_1.existsSync)(currentSqlFile)) {
|
|
21
21
|
currentSql = await fs_1.promises.readFile(currentSqlFile, 'utf8');
|
|
22
22
|
const currentSqlWithoutComments = currentSql.replace(/(--.*)|(((\/\*)+?[\w\W]+?(\*\/)+))/gm, '');
|
|
23
23
|
const nonEmptyCurrentSqlLines = currentSqlWithoutComments.match(/^[^\S\r\n]*\S.*$/gm);
|
|
@@ -26,7 +26,7 @@ const createSqlDefineFunctionsMigration = async (migrationFolderPath, postfixCon
|
|
|
26
26
|
throw new Error('Please ensure that your current.sql file is empty/only contains comments.');
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
const defineFunctions = await fs_1.promises.readFile(path_1.join(getPathToDefinitionsFolder(), 'define-functions.sql'), 'utf8');
|
|
29
|
+
const defineFunctions = await fs_1.promises.readFile((0, path_1.join)(getPathToDefinitionsFolder(), 'define-functions.sql'), 'utf8');
|
|
30
30
|
const migrationContent = `--! Message: upgrade SQL define functions
|
|
31
31
|
|
|
32
32
|
${defineFunctions}
|
|
@@ -42,8 +42,8 @@ exports.createSqlDefineFunctionsMigration = createSqlDefineFunctionsMigration;
|
|
|
42
42
|
* @param migrationFolderPath - the path to the migration folder path where the current.sql file should be created.
|
|
43
43
|
*/
|
|
44
44
|
const createSqlMultitenancyDefineFunctionsMigration = async (migrationFolderPath) => {
|
|
45
|
-
const multitenancyDefineFunctions = await fs_1.promises.readFile(path_1.join(getPathToDefinitionsFolder(), 'define-multitenancy-functions.sql'), 'utf8');
|
|
46
|
-
await exports.createSqlDefineFunctionsMigration(migrationFolderPath, multitenancyDefineFunctions);
|
|
45
|
+
const multitenancyDefineFunctions = await fs_1.promises.readFile((0, path_1.join)(getPathToDefinitionsFolder(), 'define-multitenancy-functions.sql'), 'utf8');
|
|
46
|
+
await (0, exports.createSqlDefineFunctionsMigration)(migrationFolderPath, multitenancyDefineFunctions);
|
|
47
47
|
};
|
|
48
48
|
exports.createSqlMultitenancyDefineFunctionsMigration = createSqlMultitenancyDefineFunctionsMigration;
|
|
49
49
|
//# sourceMappingURL=create-sql-define-functions-migration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-sql-define-functions-migration.js","sourceRoot":"","sources":["../../src/migrations/create-sql-define-functions-migration.ts"],"names":[],"mappings":";;;AAAA,2BAAiD;AACjD,+BAAqC;AAErC,MAAM,0BAA0B,GAAG,GAAW,EAAE;IAC9C,OAAO,cAAO,
|
|
1
|
+
{"version":3,"file":"create-sql-define-functions-migration.js","sourceRoot":"","sources":["../../src/migrations/create-sql-define-functions-migration.ts"],"names":[],"mappings":";;;AAAA,2BAAiD;AACjD,+BAAqC;AAErC,MAAM,0BAA0B,GAAG,GAAW,EAAE;IAC9C,OAAO,IAAA,cAAO,EAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,YAAY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B,EACnB,2BAA2B,CAC5B,CAAC;AACJ,CAAC,CAAC;AAXW,QAAA,6CAA6C,iDAWxD"}
|
package/dist/migrations/utils.js
CHANGED
|
@@ -25,10 +25,10 @@ const runSqlScripts = async (settings, dirPath, logger) => {
|
|
|
25
25
|
try {
|
|
26
26
|
for (var sortedList_1 = __asyncValues(sortedList), sortedList_1_1; sortedList_1_1 = await sortedList_1.next(), !sortedList_1_1.done;) {
|
|
27
27
|
const { path } = sortedList_1_1.value;
|
|
28
|
-
const scriptPath = path_1.join(dirPath, path);
|
|
28
|
+
const scriptPath = (0, path_1.join)(dirPath, path);
|
|
29
29
|
const content = await fs_1.promises.readFile(scriptPath, 'utf8');
|
|
30
30
|
logger.debug(`Running Script: '${scriptPath}'`);
|
|
31
|
-
await graphile_migrate_1.run(settings, content, path);
|
|
31
|
+
await (0, graphile_migrate_1.run)(settings, content, path);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -49,7 +49,7 @@ const runCurrentSql = async (settings, logger) => {
|
|
|
49
49
|
const path = 'migrations/current.sql';
|
|
50
50
|
const content = await fs_1.promises.readFile(path, 'utf8');
|
|
51
51
|
logger.debug(`Running Script: '${path}'`);
|
|
52
|
-
await graphile_migrate_1.run(settings, content, path);
|
|
52
|
+
await (0, graphile_migrate_1.run)(settings, content, path);
|
|
53
53
|
};
|
|
54
54
|
exports.runCurrentSql = runCurrentSql;
|
|
55
55
|
/**
|
|
@@ -68,11 +68,11 @@ exports.runCurrentSql = runCurrentSql;
|
|
|
68
68
|
```
|
|
69
69
|
*/
|
|
70
70
|
const getBeforeMigrationScripts = async () => {
|
|
71
|
-
const executionPath = path_1.join(process.cwd(), 'migrations');
|
|
72
|
-
const dirPath = path_1.resolve(__dirname, '..', '..', 'migrations', 'before-migration');
|
|
71
|
+
const executionPath = (0, path_1.join)(process.cwd(), 'migrations');
|
|
72
|
+
const dirPath = (0, path_1.resolve)(__dirname, '..', '..', 'migrations', 'before-migration');
|
|
73
73
|
return (await readdir.promise(dirPath, { fileFilter: '*.sql' }))
|
|
74
74
|
.sort((a, b) => a.path.localeCompare(b.path))
|
|
75
|
-
.map((file) => path_1.relative(executionPath, file.fullPath));
|
|
75
|
+
.map((file) => (0, path_1.relative)(executionPath, file.fullPath));
|
|
76
76
|
};
|
|
77
77
|
exports.getBeforeMigrationScripts = getBeforeMigrationScripts;
|
|
78
78
|
/**
|
|
@@ -86,15 +86,15 @@ const getGraphileBuildPgWatchFixturesPath = () => {
|
|
|
86
86
|
// Directory structure is traversed manually, because we want to first check project node_modules, and then repository node_modules.
|
|
87
87
|
// require.resolve is not useful here, because it will resolve a path to `graphile-build-pg` which is installed in this lib, and not in target project (which can be different).
|
|
88
88
|
while (lastPath !== startPath) {
|
|
89
|
-
const lookupPath = path_1.join(startPath, 'node_modules', 'graphile-build-pg', 'res', 'watch-fixtures.sql');
|
|
90
|
-
if (fs_1.existsSync(lookupPath)) {
|
|
91
|
-
return path_1.relative(path_1.join(process.cwd(), 'migrations'), lookupPath);
|
|
89
|
+
const lookupPath = (0, path_1.join)(startPath, 'node_modules', 'graphile-build-pg', 'res', 'watch-fixtures.sql');
|
|
90
|
+
if ((0, fs_1.existsSync)(lookupPath)) {
|
|
91
|
+
return (0, path_1.relative)((0, path_1.join)(process.cwd(), 'migrations'), lookupPath);
|
|
92
92
|
}
|
|
93
93
|
else {
|
|
94
94
|
// Preserve currently checked path for while condition comparison
|
|
95
95
|
lastPath = startPath;
|
|
96
96
|
// Remove last segment from path
|
|
97
|
-
startPath = path_1.normalize(path_1.join(startPath, '..'));
|
|
97
|
+
startPath = (0, path_1.normalize)((0, path_1.join)(startPath, '..'));
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
throw Error('`node_modules\\graphile-build-pg\\res\\watch-fixtures.sql` file not found. Please make sure that `graphile-build-pg` is installed.');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/migrations/utils.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,+BAA+B;AAC/B,2BAAiD;AACjD,uDAAuC;AAEvC,+BAA0D;AAC1D,oCAAoC;AAGpC;;;;;GAKG;AACI,MAAM,aAAa,GAAG,KAAK,EAChC,QAAkB,EAClB,OAAe,EACf,MAAgB,EACD,EAAE;;IACjB,MAAM,UAAU,GAAG,CACjB,MAAM,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CACxD,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;;QAC/C,KAA6B,IAAA,eAAA,cAAA,UAAU,CAAA,gBAAA;YAA5B,MAAM,EAAE,IAAI,EAAE,uBAAA,CAAA;YACvB,MAAM,UAAU,GAAG,WAAI,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/migrations/utils.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,+BAA+B;AAC/B,2BAAiD;AACjD,uDAAuC;AAEvC,+BAA0D;AAC1D,oCAAoC;AAGpC;;;;;GAKG;AACI,MAAM,aAAa,GAAG,KAAK,EAChC,QAAkB,EAClB,OAAe,EACf,MAAgB,EACD,EAAE;;IACjB,MAAM,UAAU,GAAG,CACjB,MAAM,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,CACxD,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;;QAC/C,KAA6B,IAAA,eAAA,cAAA,UAAU,CAAA,gBAAA;YAA5B,MAAM,EAAE,IAAI,EAAE,uBAAA,CAAA;YACvB,MAAM,UAAU,GAAG,IA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C,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,eAAQ,EAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC3D,CAAC,CAAC;AAZW,QAAA,yBAAyB,6BAYpC;AAEF;;;;GAIG;AACI,MAAM,mCAAmC,GAAG,GAAW,EAAE;IAC9D,IAAI,SAAS,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC9B,IAAI,QAAQ,GAAG,EAAE,CAAC;IAClB,oIAAoI;IACpI,gLAAgL;IAChL,OAAO,QAAQ,KAAK,SAAS,EAAE;QAC7B,MAAM,UAAU,GAAG,IAAA,WAAI,EACrB,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,KAAK,EACL,oBAAoB,CACrB,CAAC;QACF,IAAI,IAAA,eAAU,EAAC,UAAU,CAAC,EAAE;YAC1B,OAAO,IAAA,eAAQ,EAAC,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,CAAC,EAAE,UAAU,CAAC,CAAC;SAChE;aAAM;YACL,iEAAiE;YACjE,QAAQ,GAAG,SAAS,CAAC;YACrB,gCAAgC;YAChC,SAAS,GAAG,IAAA,gBAAS,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC;SAC9C;KACF;IACD,MAAM,KAAK,CACT,oIAAoI,CACrI,CAAC;AACJ,CAAC,CAAC;AAzBW,QAAA,mCAAmC,uCAyB9C"}
|
|
@@ -10,14 +10,14 @@ const db_1 = require("zapatos/db");
|
|
|
10
10
|
* @param callback - Callback where queries are executed.
|
|
11
11
|
*/
|
|
12
12
|
const transactionWithContext = async (pool, isolationLevel, pgSettings = {}, callback) => {
|
|
13
|
-
return db_1.transaction(pool, isolationLevel, async (ctx) => {
|
|
13
|
+
return (0, db_1.transaction)(pool, isolationLevel, async (ctx) => {
|
|
14
14
|
for (const property in pgSettings) {
|
|
15
15
|
if (!Object.prototype.hasOwnProperty.call(pgSettings, property)) {
|
|
16
16
|
continue;
|
|
17
17
|
}
|
|
18
|
-
const key = db_1.param(property);
|
|
19
|
-
const val = db_1.param(pgSettings[property]);
|
|
20
|
-
await db_1.sql `SELECT set_config(${key}, ${val}, TRUE)`.run(ctx);
|
|
18
|
+
const key = (0, db_1.param)(property);
|
|
19
|
+
const val = (0, db_1.param)(pgSettings[property]);
|
|
20
|
+
await (0, db_1.sql) `SELECT set_config(${key}, ${val}, TRUE)`.run(ctx);
|
|
21
21
|
}
|
|
22
22
|
return callback(ctx);
|
|
23
23
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-with-context.js","sourceRoot":"","sources":["../../src/zapatos/transaction-with-context.ts"],"names":[],"mappings":";;;AACA,mCAAgF;AAIhF;;;;;;GAMG;AACI,MAAM,sBAAsB,GAAG,KAAK,EACzC,IAAc,EACd,cAA8B,EAC9B,aAEI,EAAE,EACN,QAA2D,EAC/C,EAAE;IACd,OAAO,gBAAW,
|
|
1
|
+
{"version":3,"file":"transaction-with-context.js","sourceRoot":"","sources":["../../src/zapatos/transaction-with-context.ts"],"names":[],"mappings":";;;AACA,mCAAgF;AAIhF;;;;;;GAMG;AACI,MAAM,sBAAsB,GAAG,KAAK,EACzC,IAAc,EACd,cAA8B,EAC9B,aAEI,EAAE,EACN,QAA2D,EAC/C,EAAE;IACd,OAAO,IAAA,gBAAW,EAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;QACrD,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE;YACjC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,EAAE;gBAC/D,SAAS;aACV;YAED,MAAM,GAAG,GAAG,IAAA,UAAK,EAAC,QAAQ,CAAC,CAAC;YAC5B,MAAM,GAAG,GAAG,IAAA,UAAK,EAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;YACxC,MAAM,IAAA,QAAG,EAAA,qBAAqB,GAAG,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;SAC7D;QACD,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AApBW,QAAA,sBAAsB,0BAoBjC"}
|