@webiny/api-core-sql 6.6.0-alpha.13 → 6.6.0-alpha.14
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/connection/SqlConnectionFeature.d.ts +10 -8
- package/connection/SqlConnectionFeature.js +5 -3
- package/connection/SqlConnectionFeature.js.map +1 -1
- package/coreStorage/SqlTenancyStorageOperationsFactory.d.ts +2 -3
- package/coreStorage/SqlTenancyStorageOperationsFactory.js.map +1 -1
- package/coreStorage/SqlTenantStorageReadiness.d.ts +19 -0
- package/coreStorage/SqlTenantStorageReadiness.js +48 -0
- package/coreStorage/SqlTenantStorageReadiness.js.map +1 -0
- package/coreStorage/feature.d.ts +4 -3
- package/coreStorage/feature.js +4 -0
- package/coreStorage/feature.js.map +1 -1
- package/feature/SqlDialect/abstractions.d.ts +15 -0
- package/feature/SqlDialect/abstractions.js +5 -0
- package/feature/SqlDialect/abstractions.js.map +1 -0
- package/feature/SqlDialect/index.d.ts +2 -0
- package/feature/SqlDialect/index.js +1 -0
- package/index.d.ts +12 -3
- package/index.js +9 -3
- package/index.js.map +1 -1
- package/package.json +6 -6
- package/schemaSetup/abstractions.d.ts +14 -2
- package/schemaSetup/abstractions.js.map +1 -1
- package/schemaSetup/index.d.ts +3 -1
- package/schemaSetup/index.js +1 -0
- package/schemaSetup/runSchemaSetupSteps.d.ts +9 -0
- package/schemaSetup/runSchemaSetupSteps.js +6 -2
- package/schemaSetup/runSchemaSetupSteps.js.map +1 -1
- package/schemaSetup/runSqlSchemaSetups.d.ts +22 -0
- package/schemaSetup/runSqlSchemaSetups.js +24 -0
- package/schemaSetup/runSqlSchemaSetups.js.map +1 -0
- package/scopeStorage/abstractions.d.ts +19 -0
- package/scopeStorage/abstractions.js +5 -0
- package/scopeStorage/abstractions.js.map +1 -0
- package/scopeStorage/index.d.ts +3 -0
- package/scopeStorage/index.js +2 -0
- package/scopeStorage/isPostgresScope.d.ts +14 -0
- package/scopeStorage/isPostgresScope.js +8 -0
- package/scopeStorage/isPostgresScope.js.map +1 -0
- package/storage/sqlTenantStorage.d.ts +44 -0
- package/storage/sqlTenantStorage.js +32 -0
- package/storage/sqlTenantStorage.js.map +1 -0
- package/storage/types.d.ts +14 -5
- package/tenancy/index.js +50 -8
- package/tenancy/index.js.map +1 -1
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { Knex } from "knex";
|
|
2
|
+
import { SqlDialect } from "../feature/SqlDialect/index.js";
|
|
2
3
|
export interface SqlConnectionConfig {
|
|
3
4
|
knex: Knex;
|
|
5
|
+
/** The connection's database family, registered as `SqlDialect`. */
|
|
6
|
+
dialect: SqlDialect.Name;
|
|
4
7
|
tableNamePrefix?: string;
|
|
5
8
|
/**
|
|
6
9
|
* The schema was set up before the API took traffic (the storage's schema setup ran), so no
|
|
@@ -10,14 +13,13 @@ export interface SqlConnectionConfig {
|
|
|
10
13
|
schemaManaged?: boolean | (() => boolean);
|
|
11
14
|
}
|
|
12
15
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
16
|
+
* A SQL storage's connection (`KnexClient`), its database family (`SqlDialect`) and its settings,
|
|
17
|
+
* the table prefix and the schema-managed setting (`SqlSchemaConfig`). Every storage part registered
|
|
18
|
+
* in a tenant scope, and every module on the storage (the Postgres CMS, the folder catalog), runs on
|
|
19
|
+
* these.
|
|
17
20
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* reads the request's tenant from it before any tenant scope exists.
|
|
21
|
+
* The default storage registers it in the root container, once per process. It holds no feature's
|
|
22
|
+
* storage, not even the tenant registry's: those register in each tenant scope (`RequestStorage`).
|
|
21
23
|
*/
|
|
22
24
|
export declare const SqlConnectionFeature: {
|
|
23
25
|
name: string;
|
|
@@ -27,4 +29,4 @@ export declare const SqlConnectionFeature: {
|
|
|
27
29
|
* Points service discovery at the manifests table of a connection. The loader is a static global of
|
|
28
30
|
* the process, not a DI registration, so a storage sets it once, when it registers in the root.
|
|
29
31
|
*/
|
|
30
|
-
export declare const setSqlServiceManifestLoader: (config: SqlConnectionConfig) => void;
|
|
32
|
+
export declare const setSqlServiceManifestLoader: (config: Omit<SqlConnectionConfig, "dialect">) => void;
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { ServiceDiscovery } from "@webiny/api-core/features/serviceDiscovery/index.js";
|
|
3
3
|
import { KnexClientFeature } from "../feature/KnexClient/index.js";
|
|
4
|
+
import { SqlDialect } from "../feature/SqlDialect/index.js";
|
|
4
5
|
import { SqlSchemaConfig } from "../schemaConfig/index.js";
|
|
5
6
|
import { SqlServiceManifestLoader } from "../serviceDiscovery/index.js";
|
|
6
7
|
import { TableManager } from "../TableManager.js";
|
|
7
|
-
import { SqlTenancyStorageOperationsFactory } from "../coreStorage/SqlTenancyStorageOperationsFactory.js";
|
|
8
8
|
const isManaged = (schemaManaged)=>"function" == typeof schemaManaged ? schemaManaged() : true === schemaManaged;
|
|
9
9
|
const SqlConnectionFeature = createFeature({
|
|
10
10
|
name: "SqlConnection",
|
|
11
|
-
register (container, { knex, tableNamePrefix, schemaManaged = false }) {
|
|
11
|
+
register (container, { knex, dialect, tableNamePrefix, schemaManaged = false }) {
|
|
12
12
|
KnexClientFeature.register(container, knex);
|
|
13
|
+
container.registerInstance(SqlDialect, {
|
|
14
|
+
name: dialect
|
|
15
|
+
});
|
|
13
16
|
container.registerInstance(SqlSchemaConfig, {
|
|
14
17
|
isManaged: ()=>isManaged(schemaManaged),
|
|
15
18
|
tableNamePrefix
|
|
16
19
|
});
|
|
17
|
-
container.register(SqlTenancyStorageOperationsFactory);
|
|
18
20
|
}
|
|
19
21
|
});
|
|
20
22
|
const setSqlServiceManifestLoader = (config)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection/SqlConnectionFeature.js","sources":["../../src/connection/SqlConnectionFeature.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport { createFeature } from \"@webiny/feature/api\";\nimport { ServiceDiscovery } from \"@webiny/api-core/features/serviceDiscovery/index.js\";\nimport { KnexClientFeature } from \"~/feature/KnexClient/index.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"connection/SqlConnectionFeature.js","sources":["../../src/connection/SqlConnectionFeature.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport { createFeature } from \"@webiny/feature/api\";\nimport { ServiceDiscovery } from \"@webiny/api-core/features/serviceDiscovery/index.js\";\nimport { KnexClientFeature } from \"~/feature/KnexClient/index.js\";\nimport { SqlDialect } from \"~/feature/SqlDialect/index.js\";\nimport { SqlSchemaConfig } from \"~/schemaConfig/index.js\";\nimport { SqlServiceManifestLoader } from \"~/serviceDiscovery/index.js\";\nimport { TableManager } from \"~/TableManager.js\";\n\nexport interface SqlConnectionConfig {\n knex: Knex;\n /** The connection's database family, registered as `SqlDialect`. */\n dialect: SqlDialect.Name;\n tableNamePrefix?: string;\n /**\n * The schema was set up before the API took traffic (the storage's schema setup ran), so no\n * storage code checks for or creates tables at runtime. Off by default: tables are created on\n * first use. A function when it can change: a server turns it on once its setup at start ran.\n */\n schemaManaged?: boolean | (() => boolean);\n}\n\nconst isManaged = (schemaManaged: SqlConnectionConfig[\"schemaManaged\"]): boolean => {\n return typeof schemaManaged === \"function\" ? schemaManaged() : schemaManaged === true;\n};\n\n/**\n * A SQL storage's connection (`KnexClient`), its database family (`SqlDialect`) and its settings,\n * the table prefix and the schema-managed setting (`SqlSchemaConfig`). Every storage part registered\n * in a tenant scope, and every module on the storage (the Postgres CMS, the folder catalog), runs on\n * these.\n *\n * The default storage registers it in the root container, once per process. It holds no feature's\n * storage, not even the tenant registry's: those register in each tenant scope (`RequestStorage`).\n */\nexport const SqlConnectionFeature = createFeature<SqlConnectionConfig>({\n name: \"SqlConnection\",\n register(container, { knex, dialect, tableNamePrefix, schemaManaged = false }) {\n KnexClientFeature.register(container, knex);\n container.registerInstance(SqlDialect, { name: dialect });\n container.registerInstance(SqlSchemaConfig, {\n isManaged: () => isManaged(schemaManaged),\n tableNamePrefix\n });\n }\n});\n\n/**\n * Points service discovery at the manifests table of a connection. The loader is a static global of\n * the process, not a DI registration, so a storage sets it once, when it registers in the root.\n */\nexport const setSqlServiceManifestLoader = (config: Omit<SqlConnectionConfig, \"dialect\">): void => {\n const tableManager = new TableManager(config.knex, config.tableNamePrefix, {\n schemaManaged: () => isManaged(config.schemaManaged)\n });\n ServiceDiscovery.setLoader(new SqlServiceManifestLoader(config.knex, tableManager));\n};\n"],"names":["isManaged","schemaManaged","SqlConnectionFeature","createFeature","container","knex","dialect","tableNamePrefix","KnexClientFeature","SqlDialect","SqlSchemaConfig","setSqlServiceManifestLoader","config","tableManager","TableManager","ServiceDiscovery","SqlServiceManifestLoader"],"mappings":";;;;;;;AAsBA,MAAMA,YAAY,CAACC,gBACR,AAAyB,cAAzB,OAAOA,gBAA+BA,kBAAkBA,AAAkB,SAAlBA;AAY5D,MAAMC,uBAAuBC,cAAmC;IACnE,MAAM;IACN,UAASC,SAAS,EAAE,EAAEC,IAAI,EAAEC,OAAO,EAAEC,eAAe,EAAEN,gBAAgB,KAAK,EAAE;QACzEO,kBAAkB,QAAQ,CAACJ,WAAWC;QACtCD,UAAU,gBAAgB,CAACK,YAAY;YAAE,MAAMH;QAAQ;QACvDF,UAAU,gBAAgB,CAACM,iBAAiB;YACxC,WAAW,IAAMV,UAAUC;YAC3BM;QACJ;IACJ;AACJ;AAMO,MAAMI,8BAA8B,CAACC;IACxC,MAAMC,eAAe,IAAIC,aAAaF,OAAO,IAAI,EAAEA,OAAO,eAAe,EAAE;QACvE,eAAe,IAAMZ,UAAUY,OAAO,aAAa;IACvD;IACAG,iBAAiB,SAAS,CAAC,IAAIC,yBAAyBJ,OAAO,IAAI,EAAEC;AACzE"}
|
|
@@ -3,9 +3,8 @@ import type { TenancyStorageOperations } from "@webiny/api-core/types/tenancy.js
|
|
|
3
3
|
import { KnexClient } from "../feature/KnexClient/index.js";
|
|
4
4
|
import { SqlSchemaConfig } from "../schemaConfig/index.js";
|
|
5
5
|
/**
|
|
6
|
-
* The tenant registry's storage on the container's connection: the tenants table only.
|
|
7
|
-
*
|
|
8
|
-
* storage) exists.
|
|
6
|
+
* The tenant registry's storage on the container's connection: the tenants table only. Root's scope
|
|
7
|
+
* reads every tenant's record from it, the request's tenant's included.
|
|
9
8
|
*/
|
|
10
9
|
declare class SqlTenancyStorageOperationsFactoryImpl implements TenancyStorageOperationsFactory.Interface {
|
|
11
10
|
private readonly knex;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coreStorage/SqlTenancyStorageOperationsFactory.js","sources":["../../src/coreStorage/SqlTenancyStorageOperationsFactory.ts"],"sourcesContent":["// A deep import: the
|
|
1
|
+
{"version":3,"file":"coreStorage/SqlTenancyStorageOperationsFactory.js","sources":["../../src/coreStorage/SqlTenancyStorageOperationsFactory.ts"],"sourcesContent":["// A deep import: the package root pulls in all of api-core.\nimport { TenancyStorageOperationsFactory } from \"@webiny/api-core/features/storageOperations/abstractions.js\";\nimport type { TenancyStorageOperations } from \"@webiny/api-core/types/tenancy.js\";\nimport { KnexClient } from \"~/feature/KnexClient/index.js\";\nimport { SqlSchemaConfig } from \"~/schemaConfig/index.js\";\nimport { TableManager } from \"~/TableManager.js\";\nimport { createStorageOperations as createTenancyStorageOperations } from \"~/tenancy/index.js\";\n\n/**\n * The tenant registry's storage on the container's connection: the tenants table only. Root's scope\n * reads every tenant's record from it, the request's tenant's included.\n */\nclass SqlTenancyStorageOperationsFactoryImpl implements TenancyStorageOperationsFactory.Interface {\n public constructor(\n private readonly knex: KnexClient.Interface,\n private readonly schemaConfig?: SqlSchemaConfig.Interface\n ) {}\n\n public create(): TenancyStorageOperations {\n const knex = this.knex.client;\n const tableManager = new TableManager(knex, this.schemaConfig?.tableNamePrefix, {\n schemaManaged: this.schemaConfig?.isManaged() === true\n });\n return createTenancyStorageOperations({ knex, tableManager });\n }\n}\n\nexport const SqlTenancyStorageOperationsFactory =\n TenancyStorageOperationsFactory.createImplementation({\n implementation: SqlTenancyStorageOperationsFactoryImpl,\n dependencies: [KnexClient, [SqlSchemaConfig, { optional: true }]]\n });\n"],"names":["SqlTenancyStorageOperationsFactoryImpl","knex","schemaConfig","tableManager","TableManager","createTenancyStorageOperations","SqlTenancyStorageOperationsFactory","TenancyStorageOperationsFactory","KnexClient","SqlSchemaConfig"],"mappings":";;;;;AAYA,MAAMA;IACF,YACqBC,IAA0B,EAC1BC,YAAwC,CAC3D;aAFmBD,IAAI,GAAJA;aACAC,YAAY,GAAZA;IAClB;IAEI,SAAmC;QACtC,MAAMD,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM;QAC7B,MAAME,eAAe,IAAIC,aAAaH,MAAM,IAAI,CAAC,YAAY,EAAE,iBAAiB;YAC5E,eAAe,IAAI,CAAC,YAAY,EAAE,gBAAgB;QACtD;QACA,OAAOI,wBAA+B;YAAEJ;YAAME;QAAa;IAC/D;AACJ;AAEO,MAAMG,qCACTC,gCAAgC,oBAAoB,CAAC;IACjD,gBAAgBP;IAChB,cAAc;QAACQ;QAAY;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TenantStorageNotReadyError, TenantStorageReadiness } from "@webiny/api-core/features/tenancy/TenantStorageReadiness/index.js";
|
|
2
|
+
import { Result } from "@webiny/feature/api";
|
|
3
|
+
import { KnexClient } from "../feature/KnexClient/index.js";
|
|
4
|
+
import { SqlSchemaConfig } from "../schemaConfig/index.js";
|
|
5
|
+
/**
|
|
6
|
+
* A SQL storage can take a new tenant when its database answers and, when its schema is managed (set
|
|
7
|
+
* up before the API took traffic, so nothing creates tables at runtime), the schema setup ran on it.
|
|
8
|
+
* An unmanaged schema creates its tables on first use, so there's nothing more to check.
|
|
9
|
+
*/
|
|
10
|
+
declare class SqlTenantStorageReadinessImpl implements TenantStorageReadiness.Interface {
|
|
11
|
+
private knexClient;
|
|
12
|
+
private schemaConfig;
|
|
13
|
+
constructor(knexClient: KnexClient.Interface, schemaConfig: SqlSchemaConfig.Interface | undefined);
|
|
14
|
+
check(): Promise<Result<void, TenantStorageNotReadyError>>;
|
|
15
|
+
}
|
|
16
|
+
export declare const SqlTenantStorageReadiness: typeof SqlTenantStorageReadinessImpl & {
|
|
17
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/tenancy/TenantStorageReadiness/abstractions").ITenantStorageReadiness>;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { TenantStorageNotReadyError, TenantStorageReadiness } from "@webiny/api-core/features/tenancy/TenantStorageReadiness/index.js";
|
|
2
|
+
import { Result } from "@webiny/feature/api";
|
|
3
|
+
import { KnexClient } from "../feature/KnexClient/index.js";
|
|
4
|
+
import { SqlSchemaConfig } from "../schemaConfig/index.js";
|
|
5
|
+
const ROLES_TABLE = "webiny_core_roles";
|
|
6
|
+
class SqlTenantStorageReadinessImpl {
|
|
7
|
+
constructor(knexClient, schemaConfig){
|
|
8
|
+
this.knexClient = knexClient;
|
|
9
|
+
this.schemaConfig = schemaConfig;
|
|
10
|
+
}
|
|
11
|
+
async check() {
|
|
12
|
+
const knex = this.knexClient.client;
|
|
13
|
+
try {
|
|
14
|
+
await knex.raw("SELECT 1");
|
|
15
|
+
} catch (error) {
|
|
16
|
+
return Result.fail(TenantStorageNotReadyError.unreachable(`the database is not reachable (${messageOf(error)}).`));
|
|
17
|
+
}
|
|
18
|
+
if (!this.schemaConfig?.isManaged()) return Result.ok();
|
|
19
|
+
const prefix = this.schemaConfig.tableNamePrefix;
|
|
20
|
+
const table = prefix ? `${prefix}_${ROLES_TABLE}` : ROLES_TABLE;
|
|
21
|
+
let hasTable;
|
|
22
|
+
try {
|
|
23
|
+
hasTable = await knex.schema.hasTable(table);
|
|
24
|
+
} catch (error) {
|
|
25
|
+
return Result.fail(TenantStorageNotReadyError.unreachable(`the database is not reachable (${messageOf(error)}).`));
|
|
26
|
+
}
|
|
27
|
+
if (!hasTable) return Result.fail(TenantStorageNotReadyError.notSetUp(`its schema is not set up (table "${table}" is missing).`));
|
|
28
|
+
return Result.ok();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function messageOf(error) {
|
|
32
|
+
return error instanceof Error ? error.message : String(error);
|
|
33
|
+
}
|
|
34
|
+
const SqlTenantStorageReadiness = TenantStorageReadiness.createImplementation({
|
|
35
|
+
implementation: SqlTenantStorageReadinessImpl,
|
|
36
|
+
dependencies: [
|
|
37
|
+
KnexClient,
|
|
38
|
+
[
|
|
39
|
+
SqlSchemaConfig,
|
|
40
|
+
{
|
|
41
|
+
optional: true
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
]
|
|
45
|
+
});
|
|
46
|
+
export { SqlTenantStorageReadiness };
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=SqlTenantStorageReadiness.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coreStorage/SqlTenantStorageReadiness.js","sources":["../../src/coreStorage/SqlTenantStorageReadiness.ts"],"sourcesContent":["// A deep import: the package root pulls in all of api-core.\nimport {\n TenantStorageNotReadyError,\n TenantStorageReadiness\n} from \"@webiny/api-core/features/tenancy/TenantStorageReadiness/index.js\";\nimport { Result } from \"@webiny/feature/api\";\nimport { KnexClient } from \"~/feature/KnexClient/index.js\";\nimport { SqlSchemaConfig } from \"~/schemaConfig/index.js\";\n\n/** A table every installation writes to (the security installer's roles). */\nconst ROLES_TABLE = \"webiny_core_roles\";\n\n/**\n * A SQL storage can take a new tenant when its database answers and, when its schema is managed (set\n * up before the API took traffic, so nothing creates tables at runtime), the schema setup ran on it.\n * An unmanaged schema creates its tables on first use, so there's nothing more to check.\n */\nclass SqlTenantStorageReadinessImpl implements TenantStorageReadiness.Interface {\n constructor(\n private knexClient: KnexClient.Interface,\n private schemaConfig: SqlSchemaConfig.Interface | undefined\n ) {}\n\n async check(): Promise<Result<void, TenantStorageNotReadyError>> {\n const knex = this.knexClient.client;\n try {\n await knex.raw(\"SELECT 1\");\n } catch (error) {\n return Result.fail(\n TenantStorageNotReadyError.unreachable(\n `the database is not reachable (${messageOf(error)}).`\n )\n );\n }\n\n if (!this.schemaConfig?.isManaged()) {\n return Result.ok();\n }\n const prefix = this.schemaConfig.tableNamePrefix;\n const table = prefix ? `${prefix}_${ROLES_TABLE}` : ROLES_TABLE;\n let hasTable: boolean;\n try {\n hasTable = await knex.schema.hasTable(table);\n } catch (error) {\n return Result.fail(\n TenantStorageNotReadyError.unreachable(\n `the database is not reachable (${messageOf(error)}).`\n )\n );\n }\n if (!hasTable) {\n return Result.fail(\n TenantStorageNotReadyError.notSetUp(\n `its schema is not set up (table \"${table}\" is missing).`\n )\n );\n }\n return Result.ok();\n }\n}\n\nfunction messageOf(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\nexport const SqlTenantStorageReadiness = TenantStorageReadiness.createImplementation({\n implementation: SqlTenantStorageReadinessImpl,\n dependencies: [KnexClient, [SqlSchemaConfig, { optional: true }]]\n});\n"],"names":["ROLES_TABLE","SqlTenantStorageReadinessImpl","knexClient","schemaConfig","knex","error","Result","TenantStorageNotReadyError","messageOf","prefix","table","hasTable","Error","String","SqlTenantStorageReadiness","TenantStorageReadiness","KnexClient","SqlSchemaConfig"],"mappings":";;;;AAUA,MAAMA,cAAc;AAOpB,MAAMC;IACF,YACYC,UAAgC,EAChCC,YAAmD,CAC7D;aAFUD,UAAU,GAAVA;aACAC,YAAY,GAAZA;IACT;IAEH,MAAM,QAA2D;QAC7D,MAAMC,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM;QACnC,IAAI;YACA,MAAMA,KAAK,GAAG,CAAC;QACnB,EAAE,OAAOC,OAAO;YACZ,OAAOC,OAAO,IAAI,CACdC,2BAA2B,WAAW,CAClC,CAAC,+BAA+B,EAAEC,UAAUH,OAAO,EAAE,CAAC;QAGlE;QAEA,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,aACpB,OAAOC,OAAO,EAAE;QAEpB,MAAMG,SAAS,IAAI,CAAC,YAAY,CAAC,eAAe;QAChD,MAAMC,QAAQD,SAAS,GAAGA,OAAO,CAAC,EAAET,aAAa,GAAGA;QACpD,IAAIW;QACJ,IAAI;YACAA,WAAW,MAAMP,KAAK,MAAM,CAAC,QAAQ,CAACM;QAC1C,EAAE,OAAOL,OAAO;YACZ,OAAOC,OAAO,IAAI,CACdC,2BAA2B,WAAW,CAClC,CAAC,+BAA+B,EAAEC,UAAUH,OAAO,EAAE,CAAC;QAGlE;QACA,IAAI,CAACM,UACD,OAAOL,OAAO,IAAI,CACdC,2BAA2B,QAAQ,CAC/B,CAAC,iCAAiC,EAAEG,MAAM,cAAc,CAAC;QAIrE,OAAOJ,OAAO,EAAE;IACpB;AACJ;AAEA,SAASE,UAAUH,KAAc;IAC7B,OAAOA,iBAAiBO,QAAQP,MAAM,OAAO,GAAGQ,OAAOR;AAC3D;AAEO,MAAMS,4BAA4BC,uBAAuB,oBAAoB,CAAC;IACjF,gBAAgBd;IAChB,cAAc;QAACe;QAAY;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrE"}
|
package/coreStorage/feature.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The SQL core storage of a
|
|
3
|
-
* `ApiCoreFeature.register` resolves and builds,
|
|
4
|
-
* `
|
|
2
|
+
* The SQL core storage of a tenant scope: the implementation of `ApiCoreStorageOperationsFactory`,
|
|
3
|
+
* which `ApiCoreFeature.register` resolves and builds, the tenant registry's
|
|
4
|
+
* (`TenancyStorageOperationsFactory`, used in root's scope and the default storage's), and the `core`
|
|
5
|
+
* schema setup step. Mirrors `ApiCoreDdbFeature`.
|
|
5
6
|
*
|
|
6
7
|
* Registered per request (by the SQL storage's `RequestStorage`). It runs on what the root holds:
|
|
7
8
|
* the connection (`KnexClient`) and the table prefix and schema-managed setting (`SqlSchemaConfig`),
|
package/coreStorage/feature.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { createFeature } from "@webiny/feature/api";
|
|
2
2
|
import { SqlApiCoreStorageOperationsFactory } from "./SqlApiCoreStorageOperationsFactory.js";
|
|
3
3
|
import { CoreSqlSchemaSetup } from "./CoreSqlSchemaSetup.js";
|
|
4
|
+
import { SqlTenancyStorageOperationsFactory } from "./SqlTenancyStorageOperationsFactory.js";
|
|
5
|
+
import { SqlTenantStorageReadiness } from "./SqlTenantStorageReadiness.js";
|
|
4
6
|
const ApiCoreSqlFeature = createFeature({
|
|
5
7
|
name: "ApiCoreSql",
|
|
6
8
|
register (container) {
|
|
7
9
|
container.register(SqlApiCoreStorageOperationsFactory);
|
|
10
|
+
container.register(SqlTenancyStorageOperationsFactory);
|
|
8
11
|
container.register(CoreSqlSchemaSetup);
|
|
12
|
+
container.register(SqlTenantStorageReadiness);
|
|
9
13
|
}
|
|
10
14
|
});
|
|
11
15
|
export { ApiCoreSqlFeature };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coreStorage/feature.js","sources":["../../src/coreStorage/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { SqlApiCoreStorageOperationsFactory } from \"./SqlApiCoreStorageOperationsFactory.js\";\nimport { CoreSqlSchemaSetup } from \"./CoreSqlSchemaSetup.js\";\n\n/**\n * The SQL core storage of a
|
|
1
|
+
{"version":3,"file":"coreStorage/feature.js","sources":["../../src/coreStorage/feature.ts"],"sourcesContent":["import { createFeature } from \"@webiny/feature/api\";\nimport { SqlApiCoreStorageOperationsFactory } from \"./SqlApiCoreStorageOperationsFactory.js\";\nimport { CoreSqlSchemaSetup } from \"./CoreSqlSchemaSetup.js\";\nimport { SqlTenancyStorageOperationsFactory } from \"./SqlTenancyStorageOperationsFactory.js\";\nimport { SqlTenantStorageReadiness } from \"./SqlTenantStorageReadiness.js\";\n\n/**\n * The SQL core storage of a tenant scope: the implementation of `ApiCoreStorageOperationsFactory`,\n * which `ApiCoreFeature.register` resolves and builds, the tenant registry's\n * (`TenancyStorageOperationsFactory`, used in root's scope and the default storage's), and the `core`\n * schema setup step. Mirrors `ApiCoreDdbFeature`.\n *\n * Registered per request (by the SQL storage's `RequestStorage`). It runs on what the root holds:\n * the connection (`KnexClient`) and the table prefix and schema-managed setting (`SqlSchemaConfig`),\n * both registered by `SqlConnectionFeature`.\n */\nexport const ApiCoreSqlFeature = createFeature({\n name: \"ApiCoreSql\",\n register(container) {\n container.register(SqlApiCoreStorageOperationsFactory);\n container.register(SqlTenancyStorageOperationsFactory);\n container.register(CoreSqlSchemaSetup);\n container.register(SqlTenantStorageReadiness);\n }\n});\n"],"names":["ApiCoreSqlFeature","createFeature","container","SqlApiCoreStorageOperationsFactory","SqlTenancyStorageOperationsFactory","CoreSqlSchemaSetup","SqlTenantStorageReadiness"],"mappings":";;;;;AAgBO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;QACnBF,UAAU,QAAQ,CAACG;QACnBH,UAAU,QAAQ,CAACI;IACvB;AACJ"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** The SQL database families the API runs on. */
|
|
2
|
+
export type SqlDialectName = "postgres" | "sqlite";
|
|
3
|
+
export interface ISqlDialect {
|
|
4
|
+
/** The database family of the connection (`KnexClient`) registered next to it. */
|
|
5
|
+
readonly name: SqlDialectName;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Which database the SQL connection talks to. Registered with the connection (`SqlConnectionFeature`),
|
|
9
|
+
* by the storage that knows it, so code that branches on the database never asks the driver.
|
|
10
|
+
*/
|
|
11
|
+
export declare const SqlDialect: import("@webiny/di").Abstraction<ISqlDialect>;
|
|
12
|
+
export declare namespace SqlDialect {
|
|
13
|
+
type Interface = ISqlDialect;
|
|
14
|
+
type Name = SqlDialectName;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"feature/SqlDialect/abstractions.js","sources":["../../../src/feature/SqlDialect/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\n\n/** The SQL database families the API runs on. */\nexport type SqlDialectName = \"postgres\" | \"sqlite\";\n\nexport interface ISqlDialect {\n /** The database family of the connection (`KnexClient`) registered next to it. */\n readonly name: SqlDialectName;\n}\n\n/**\n * Which database the SQL connection talks to. Registered with the connection (`SqlConnectionFeature`),\n * by the storage that knows it, so code that branches on the database never asks the driver.\n */\nexport const SqlDialect = createAbstraction<ISqlDialect>(\"Db/Sql/SqlDialect\");\n\nexport namespace SqlDialect {\n export type Interface = ISqlDialect;\n export type Name = SqlDialectName;\n}\n"],"names":["SqlDialect","createAbstraction"],"mappings":";AAcO,MAAMA,aAAaC,kBAA+B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SqlDialect } from "./abstractions.js";
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Knex } from "knex";
|
|
2
|
+
import { SqlDialect } from "./feature/SqlDialect/index.js";
|
|
2
3
|
export { createApiCoreSql } from "./createApiCoreSql.js";
|
|
3
4
|
export { ApiCoreSqlFeature } from "./coreStorage/index.js";
|
|
4
5
|
export { SqlConnectionFeature, setSqlServiceManifestLoader } from "./connection/index.js";
|
|
@@ -7,18 +8,26 @@ export { getSqlTablePrefix } from "./getSqlTablePrefix.js";
|
|
|
7
8
|
export { TableManager } from "./TableManager.js";
|
|
8
9
|
export type { TableManagerOptions } from "./TableManager.js";
|
|
9
10
|
export { SqlSchemaConfig } from "./schemaConfig/index.js";
|
|
10
|
-
export { SqlSchemaSetup, SqlSchemaSetupRunner, runSchemaSetupSteps } from "./schemaSetup/index.js";
|
|
11
|
-
export type { ISqlSchemaSetupRequest, RequiredSqlSchemaSetup, RunSchemaSetupStepsParams, SqlSchemaSetupRunParams } from "./schemaSetup/index.js";
|
|
11
|
+
export { SqlSchemaSetup, SqlSchemaSetupRunner, runSchemaSetupSteps, runSqlSchemaSetups } from "./schemaSetup/index.js";
|
|
12
|
+
export type { ISqlSchemaSetupRequest, ISqlSchemaSetupRequestOptions, RunSqlSchemaSetupsParams, SqlSchemaSetupResult, RequiredSqlSchemaSetup, RunSchemaSetupStepsParams, SqlSchemaSetupRunParams } from "./schemaSetup/index.js";
|
|
12
13
|
export { getSchemaMemory } from "./schemaMemory/getSchemaMemory.js";
|
|
13
14
|
export { getConnectionKey } from "./schemaMemory/getConnectionKey.js";
|
|
14
15
|
export { ensureTable, createTableIfMissing, recordTable } from "./schemaMemory/ensureTable.js";
|
|
15
16
|
export type { EnsureTableParams, TableCreator, TableUpgrade } from "./schemaMemory/ensureTable.js";
|
|
16
17
|
export type { ISchemaMemory } from "./schemaMemory/getSchemaMemory.js";
|
|
17
18
|
export type { SqlStorage } from "./storage/types.js";
|
|
19
|
+
export { createSqlRequestStorage, createSqlTenantStorageBackend, registerSqlScopeStorages, registerTenantStorageBackend } from "./storage/sqlTenantStorage.js";
|
|
20
|
+
export type { CreateSqlTenantStorageBackendParams, RegisterSqlStorageParts, SqlStorageIdentityParams } from "./storage/sqlTenantStorage.js";
|
|
21
|
+
export { SqlScopeStorage, isPostgresScope } from "./scopeStorage/index.js";
|
|
22
|
+
export type { ISqlScopeStorage } from "./scopeStorage/index.js";
|
|
18
23
|
export * from "./connectionRetry/index.js";
|
|
19
24
|
export { SqlServiceManifestLoader, SqlServiceManifestWriter } from "./serviceDiscovery/index.js";
|
|
20
25
|
export { KnexClient } from "./feature/KnexClient/index.js";
|
|
26
|
+
export { SqlDialect };
|
|
27
|
+
export type { ISqlDialect, SqlDialectName } from "./feature/SqlDialect/index.js";
|
|
21
28
|
interface IRegisterApiCoreSqlExtension {
|
|
22
29
|
knex: Knex;
|
|
30
|
+
/** The connection's database family, registered as `SqlDialect` (`isPostgresScope` reads it). */
|
|
31
|
+
dialect: SqlDialect.Name;
|
|
23
32
|
}
|
|
24
|
-
export declare const registerSQLCore: ({ knex }: IRegisterApiCoreSqlExtension) => import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types.js").Context>;
|
|
33
|
+
export declare const registerSQLCore: ({ knex, dialect }: IRegisterApiCoreSqlExtension) => import("@webiny/handler").RegisterExtensionPlugin<import("@webiny/handler/types.js").Context>;
|
package/index.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { createRegisterExtensionPlugin } from "@webiny/handler";
|
|
2
2
|
import { KnexClient, KnexClientFeature } from "./feature/KnexClient/index.js";
|
|
3
|
+
import { SqlDialect } from "./feature/SqlDialect/index.js";
|
|
3
4
|
export * from "./connectionRetry/index.js";
|
|
4
|
-
const registerSQLCore = ({ knex })=>createRegisterExtensionPlugin(async (context)=>{
|
|
5
|
+
const registerSQLCore = ({ knex, dialect })=>createRegisterExtensionPlugin(async (context)=>{
|
|
5
6
|
KnexClientFeature.register(context.container, knex);
|
|
7
|
+
context.container.registerInstance(SqlDialect, {
|
|
8
|
+
name: dialect
|
|
9
|
+
});
|
|
6
10
|
});
|
|
7
11
|
export { createApiCoreSql } from "./createApiCoreSql.js";
|
|
8
12
|
export { ApiCoreSqlFeature } from "./coreStorage/index.js";
|
|
@@ -10,11 +14,13 @@ export { SqlConnectionFeature, setSqlServiceManifestLoader } from "./connection/
|
|
|
10
14
|
export { getSqlTablePrefix } from "./getSqlTablePrefix.js";
|
|
11
15
|
export { TableManager } from "./TableManager.js";
|
|
12
16
|
export { SqlSchemaConfig } from "./schemaConfig/index.js";
|
|
13
|
-
export { SqlSchemaSetup, SqlSchemaSetupRunner, runSchemaSetupSteps } from "./schemaSetup/index.js";
|
|
17
|
+
export { SqlSchemaSetup, SqlSchemaSetupRunner, runSchemaSetupSteps, runSqlSchemaSetups } from "./schemaSetup/index.js";
|
|
14
18
|
export { getSchemaMemory } from "./schemaMemory/getSchemaMemory.js";
|
|
15
19
|
export { getConnectionKey } from "./schemaMemory/getConnectionKey.js";
|
|
16
20
|
export { createTableIfMissing, ensureTable, recordTable } from "./schemaMemory/ensureTable.js";
|
|
21
|
+
export { createSqlRequestStorage, createSqlTenantStorageBackend, registerSqlScopeStorages, registerTenantStorageBackend } from "./storage/sqlTenantStorage.js";
|
|
22
|
+
export { SqlScopeStorage, isPostgresScope } from "./scopeStorage/index.js";
|
|
17
23
|
export { SqlServiceManifestLoader, SqlServiceManifestWriter } from "./serviceDiscovery/index.js";
|
|
18
|
-
export { KnexClient, registerSQLCore };
|
|
24
|
+
export { KnexClient, SqlDialect, registerSQLCore };
|
|
19
25
|
|
|
20
26
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { createRegisterExtensionPlugin } from \"@webiny/handler\";\nimport type { Knex } from \"knex\";\nimport { KnexClientFeature } from \"./feature/KnexClient/index.js\";\n\nexport { createApiCoreSql } from \"./createApiCoreSql.js\";\nexport { ApiCoreSqlFeature } from \"./coreStorage/index.js\";\nexport { SqlConnectionFeature, setSqlServiceManifestLoader } from \"./connection/index.js\";\nexport type { SqlConnectionConfig } from \"./connection/index.js\";\nexport { getSqlTablePrefix } from \"./getSqlTablePrefix.js\";\nexport { TableManager } from \"./TableManager.js\";\nexport type { TableManagerOptions } from \"./TableManager.js\";\nexport { SqlSchemaConfig } from \"./schemaConfig/index.js\";\nexport {
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { createRegisterExtensionPlugin } from \"@webiny/handler\";\nimport type { Knex } from \"knex\";\nimport { KnexClientFeature } from \"./feature/KnexClient/index.js\";\nimport { SqlDialect } from \"./feature/SqlDialect/index.js\";\n\nexport { createApiCoreSql } from \"./createApiCoreSql.js\";\nexport { ApiCoreSqlFeature } from \"./coreStorage/index.js\";\nexport { SqlConnectionFeature, setSqlServiceManifestLoader } from \"./connection/index.js\";\nexport type { SqlConnectionConfig } from \"./connection/index.js\";\nexport { getSqlTablePrefix } from \"./getSqlTablePrefix.js\";\nexport { TableManager } from \"./TableManager.js\";\nexport type { TableManagerOptions } from \"./TableManager.js\";\nexport { SqlSchemaConfig } from \"./schemaConfig/index.js\";\nexport {\n SqlSchemaSetup,\n SqlSchemaSetupRunner,\n runSchemaSetupSteps,\n runSqlSchemaSetups\n} from \"./schemaSetup/index.js\";\nexport type {\n ISqlSchemaSetupRequest,\n ISqlSchemaSetupRequestOptions,\n RunSqlSchemaSetupsParams,\n SqlSchemaSetupResult,\n RequiredSqlSchemaSetup,\n RunSchemaSetupStepsParams,\n SqlSchemaSetupRunParams\n} from \"./schemaSetup/index.js\";\nexport { getSchemaMemory } from \"./schemaMemory/getSchemaMemory.js\";\nexport { getConnectionKey } from \"./schemaMemory/getConnectionKey.js\";\nexport { ensureTable, createTableIfMissing, recordTable } from \"./schemaMemory/ensureTable.js\";\nexport type { EnsureTableParams, TableCreator, TableUpgrade } from \"./schemaMemory/ensureTable.js\";\nexport type { ISchemaMemory } from \"./schemaMemory/getSchemaMemory.js\";\nexport type { SqlStorage } from \"./storage/types.js\";\nexport {\n createSqlRequestStorage,\n createSqlTenantStorageBackend,\n registerSqlScopeStorages,\n registerTenantStorageBackend\n} from \"./storage/sqlTenantStorage.js\";\nexport type {\n CreateSqlTenantStorageBackendParams,\n RegisterSqlStorageParts,\n SqlStorageIdentityParams\n} from \"./storage/sqlTenantStorage.js\";\nexport { SqlScopeStorage, isPostgresScope } from \"./scopeStorage/index.js\";\nexport type { ISqlScopeStorage } from \"./scopeStorage/index.js\";\nexport * from \"./connectionRetry/index.js\";\nexport { SqlServiceManifestLoader, SqlServiceManifestWriter } from \"./serviceDiscovery/index.js\";\n\nexport { KnexClient } from \"./feature/KnexClient/index.js\";\nexport { SqlDialect };\nexport type { ISqlDialect, SqlDialectName } from \"./feature/SqlDialect/index.js\";\n\ninterface IRegisterApiCoreSqlExtension {\n knex: Knex;\n /** The connection's database family, registered as `SqlDialect` (`isPostgresScope` reads it). */\n dialect: SqlDialect.Name;\n}\n\nexport const registerSQLCore = ({ knex, dialect }: IRegisterApiCoreSqlExtension) => {\n return createRegisterExtensionPlugin(async context => {\n KnexClientFeature.register(context.container, knex);\n context.container.registerInstance(SqlDialect, { name: dialect });\n });\n};\n"],"names":["registerSQLCore","knex","dialect","createRegisterExtensionPlugin","context","KnexClientFeature","SqlDialect"],"mappings":";;;;AA4DO,MAAMA,kBAAkB,CAAC,EAAEC,IAAI,EAAEC,OAAO,EAAgC,GACpEC,8BAA8B,OAAMC;QACvCC,kBAAkB,QAAQ,CAACD,QAAQ,SAAS,EAAEH;QAC9CG,QAAQ,SAAS,CAAC,gBAAgB,CAACE,YAAY;YAAE,MAAMJ;QAAQ;IACnE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-core-sql",
|
|
3
|
-
"version": "6.6.0-alpha.
|
|
3
|
+
"version": "6.6.0-alpha.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"author": "Webiny Ltd.",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@webiny/api-core": "6.6.0-alpha.
|
|
25
|
-
"@webiny/error": "6.6.0-alpha.
|
|
26
|
-
"@webiny/feature": "6.6.0-alpha.
|
|
27
|
-
"@webiny/handler": "6.6.0-alpha.
|
|
24
|
+
"@webiny/api-core": "6.6.0-alpha.14",
|
|
25
|
+
"@webiny/error": "6.6.0-alpha.14",
|
|
26
|
+
"@webiny/feature": "6.6.0-alpha.14",
|
|
27
|
+
"@webiny/handler": "6.6.0-alpha.14",
|
|
28
28
|
"knex": "3.3.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@webiny/build-tools": "6.6.0-alpha.
|
|
31
|
+
"@webiny/build-tools": "6.6.0-alpha.14",
|
|
32
32
|
"better-sqlite3": "13.2.0",
|
|
33
33
|
"pg": "8.23.1",
|
|
34
34
|
"typescript": "7.0.2",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Knex } from "knex";
|
|
2
2
|
import type { Container } from "@webiny/feature/api";
|
|
3
|
+
import type { TenantStorageBackend } from "@webiny/api-core/features/tenancy/TenantStorages/abstractions.js";
|
|
3
4
|
export interface ISqlSchemaSetup {
|
|
4
5
|
/**
|
|
5
6
|
* What the step sets up, as a short id (`core`, `websockets`, `cms`, `aco`). The runner reports
|
|
@@ -26,13 +27,20 @@ export declare const SqlSchemaSetup: import("@webiny/di").Abstraction<ISqlSchema
|
|
|
26
27
|
export declare namespace SqlSchemaSetup {
|
|
27
28
|
type Interface = ISqlSchemaSetup;
|
|
28
29
|
}
|
|
30
|
+
export interface ISqlSchemaSetupRequestOptions {
|
|
31
|
+
/**
|
|
32
|
+
* The storage to register, as a tenant scope on it would: an extra storage's backend, bound to
|
|
33
|
+
* the setup's connection. Default: the default storage's.
|
|
34
|
+
*/
|
|
35
|
+
backend?: TenantStorageBackend.Interface;
|
|
36
|
+
}
|
|
29
37
|
/**
|
|
30
38
|
* What a request registers, as the transport builds every request's container: its storages (every
|
|
31
39
|
* `RequestStorage`), the API's features and the project's extensions. The schema setup builds its
|
|
32
40
|
* container with it, so it sets up exactly the tables the API uses, with their settings.
|
|
33
41
|
*/
|
|
34
42
|
export interface ISqlSchemaSetupRequest {
|
|
35
|
-
register(container: Container): Promise<void>;
|
|
43
|
+
register(container: Container, options?: ISqlSchemaSetupRequestOptions): Promise<void>;
|
|
36
44
|
}
|
|
37
45
|
export interface SqlSchemaSetupRunParams {
|
|
38
46
|
/** Registers a request's parts in the setup's container. */
|
|
@@ -44,6 +52,8 @@ export interface SqlSchemaSetupRunParams {
|
|
|
44
52
|
knex?: Knex;
|
|
45
53
|
}
|
|
46
54
|
export interface ISqlSchemaSetupRunner {
|
|
55
|
+
/** The id of the storage it sets up: `default`, or an extra storage's. Default: `default`. */
|
|
56
|
+
readonly storage?: string;
|
|
47
57
|
/**
|
|
48
58
|
* Creates every table, index and function the API uses: opens the setup's transaction (on
|
|
49
59
|
* Postgres, behind an advisory lock), builds a container on it the way a request's is built,
|
|
@@ -54,7 +64,8 @@ export interface ISqlSchemaSetupRunner {
|
|
|
54
64
|
run(params: SqlSchemaSetupRunParams): Promise<string[]>;
|
|
55
65
|
}
|
|
56
66
|
/**
|
|
57
|
-
* Runs the schema setup of
|
|
67
|
+
* Runs the schema setup of one SQL storage. Each storage registers its implementation in the root,
|
|
68
|
+
* the default storage and every extra one (`runSqlSchemaSetups` runs them all):
|
|
58
69
|
* it knows how its engine runs DDL safely (a transaction behind an advisory lock on Postgres, a plain
|
|
59
70
|
* transaction on SQLite) and which modules it can't run without. The transport runs it before the
|
|
60
71
|
* API takes traffic: the standalone server at start, the Lambda API on its schema-setup event.
|
|
@@ -63,5 +74,6 @@ export declare const SqlSchemaSetupRunner: import("@webiny/di").Abstraction<ISql
|
|
|
63
74
|
export declare namespace SqlSchemaSetupRunner {
|
|
64
75
|
type Interface = ISqlSchemaSetupRunner;
|
|
65
76
|
type Request = ISqlSchemaSetupRequest;
|
|
77
|
+
type RequestOptions = ISqlSchemaSetupRequestOptions;
|
|
66
78
|
type RunParams = SqlSchemaSetupRunParams;
|
|
67
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaSetup/abstractions.js","sources":["../../src/schemaSetup/abstractions.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type { Container } from \"@webiny/feature/api\";\nimport { createAbstraction } from \"@webiny/feature/api\";\n\nexport interface ISqlSchemaSetup {\n /**\n * What the step sets up, as a short id (`core`, `websockets`, `cms`, `aco`). The runner reports\n * the steps it ran by these names, and can check that a module it needs registered its step.\n */\n readonly name: string;\n /**\n * Brings the step's tables, indexes and functions up to date, whatever the schema-managed\n * setting. Safe to run again: what already exists is kept. It never drops a table or a column,\n * but a step may migrate in place. The Postgres CMS, for one, adds columns\n * (`ALTER TABLE … ADD COLUMN IF NOT EXISTS`), changes column statistics, replaces its trigger\n * functions, replaces the old count triggers and rebuilds the count rows from the search table\n * once. The database user that runs setup needs the rights for that.\n */\n setup(): Promise<void>;\n}\n\n/**\n * One step of the schema setup. Every part that owns tables registers its own step in a request's\n * container: the storage's parts (core, audit logs, websockets), the transport's login storage, and\n * the modules registered through the project's extensions (the Postgres CMS, the folder catalog).\n * The setup runner runs every step it finds, so it doesn't need to know which modules exist.\n */\nexport const SqlSchemaSetup = createAbstraction<ISqlSchemaSetup>(\"Db/Sql/SchemaSetup\");\n\nexport namespace SqlSchemaSetup {\n export type Interface = ISqlSchemaSetup;\n}\n\n/**\n * What a request registers, as the transport builds every request's container: its storages (every\n * `RequestStorage`), the API's features and the project's extensions. The schema setup builds its\n * container with it, so it sets up exactly the tables the API uses, with their settings.\n */\nexport interface ISqlSchemaSetupRequest {\n register(container: Container): Promise<void>;\n}\n\nexport interface SqlSchemaSetupRunParams {\n /** Registers a request's parts in the setup's container. */\n request: ISqlSchemaSetupRequest;\n /**\n * The connection to set the schema up on. Defaults to the storage's. The caller closes it.\n * On Lambda, setup goes to the database's writer, not through the proxy the API uses.\n */\n knex?: Knex;\n}\n\nexport interface ISqlSchemaSetupRunner {\n /**\n * Creates every table, index and function the API uses: opens the setup's transaction (on\n * Postgres, behind an advisory lock), builds a container on it the way a request's is built,\n * and runs every `SqlSchemaSetup` step in it. Keeps what exists, and is safe to run on every\n * start or deploy (see `ISqlSchemaSetup.setup` for what a step may migrate). Afterwards the storage is schema-managed. Returns the names of the steps it\n * ran.\n */\n run(params: SqlSchemaSetupRunParams): Promise<string[]>;\n}\n\n/**\n * Runs the schema setup of
|
|
1
|
+
{"version":3,"file":"schemaSetup/abstractions.js","sources":["../../src/schemaSetup/abstractions.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type { Container } from \"@webiny/feature/api\";\nimport { createAbstraction } from \"@webiny/feature/api\";\n// A deep import: the package root pulls in all of api-core.\nimport type { TenantStorageBackend } from \"@webiny/api-core/features/tenancy/TenantStorages/abstractions.js\";\n\nexport interface ISqlSchemaSetup {\n /**\n * What the step sets up, as a short id (`core`, `websockets`, `cms`, `aco`). The runner reports\n * the steps it ran by these names, and can check that a module it needs registered its step.\n */\n readonly name: string;\n /**\n * Brings the step's tables, indexes and functions up to date, whatever the schema-managed\n * setting. Safe to run again: what already exists is kept. It never drops a table or a column,\n * but a step may migrate in place. The Postgres CMS, for one, adds columns\n * (`ALTER TABLE … ADD COLUMN IF NOT EXISTS`), changes column statistics, replaces its trigger\n * functions, replaces the old count triggers and rebuilds the count rows from the search table\n * once. The database user that runs setup needs the rights for that.\n */\n setup(): Promise<void>;\n}\n\n/**\n * One step of the schema setup. Every part that owns tables registers its own step in a request's\n * container: the storage's parts (core, audit logs, websockets), the transport's login storage, and\n * the modules registered through the project's extensions (the Postgres CMS, the folder catalog).\n * The setup runner runs every step it finds, so it doesn't need to know which modules exist.\n */\nexport const SqlSchemaSetup = createAbstraction<ISqlSchemaSetup>(\"Db/Sql/SchemaSetup\");\n\nexport namespace SqlSchemaSetup {\n export type Interface = ISqlSchemaSetup;\n}\n\nexport interface ISqlSchemaSetupRequestOptions {\n /**\n * The storage to register, as a tenant scope on it would: an extra storage's backend, bound to\n * the setup's connection. Default: the default storage's.\n */\n backend?: TenantStorageBackend.Interface;\n}\n\n/**\n * What a request registers, as the transport builds every request's container: its storages (every\n * `RequestStorage`), the API's features and the project's extensions. The schema setup builds its\n * container with it, so it sets up exactly the tables the API uses, with their settings.\n */\nexport interface ISqlSchemaSetupRequest {\n register(container: Container, options?: ISqlSchemaSetupRequestOptions): Promise<void>;\n}\n\nexport interface SqlSchemaSetupRunParams {\n /** Registers a request's parts in the setup's container. */\n request: ISqlSchemaSetupRequest;\n /**\n * The connection to set the schema up on. Defaults to the storage's. The caller closes it.\n * On Lambda, setup goes to the database's writer, not through the proxy the API uses.\n */\n knex?: Knex;\n}\n\nexport interface ISqlSchemaSetupRunner {\n /** The id of the storage it sets up: `default`, or an extra storage's. Default: `default`. */\n readonly storage?: string;\n /**\n * Creates every table, index and function the API uses: opens the setup's transaction (on\n * Postgres, behind an advisory lock), builds a container on it the way a request's is built,\n * and runs every `SqlSchemaSetup` step in it. Keeps what exists, and is safe to run on every\n * start or deploy (see `ISqlSchemaSetup.setup` for what a step may migrate). Afterwards the storage is schema-managed. Returns the names of the steps it\n * ran.\n */\n run(params: SqlSchemaSetupRunParams): Promise<string[]>;\n}\n\n/**\n * Runs the schema setup of one SQL storage. Each storage registers its implementation in the root,\n * the default storage and every extra one (`runSqlSchemaSetups` runs them all):\n * it knows how its engine runs DDL safely (a transaction behind an advisory lock on Postgres, a plain\n * transaction on SQLite) and which modules it can't run without. The transport runs it before the\n * API takes traffic: the standalone server at start, the Lambda API on its schema-setup event.\n */\nexport const SqlSchemaSetupRunner = createAbstraction<ISqlSchemaSetupRunner>(\n \"Db/Sql/SchemaSetupRunner\"\n);\n\nexport namespace SqlSchemaSetupRunner {\n export type Interface = ISqlSchemaSetupRunner;\n export type Request = ISqlSchemaSetupRequest;\n export type RequestOptions = ISqlSchemaSetupRequestOptions;\n export type RunParams = SqlSchemaSetupRunParams;\n}\n"],"names":["SqlSchemaSetup","createAbstraction","SqlSchemaSetupRunner"],"mappings":";AA6BO,MAAMA,iBAAiBC,kBAAmC;AAqD1D,MAAMC,uBAAuBD,kBAChC"}
|
package/schemaSetup/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { SqlSchemaSetup, SqlSchemaSetupRunner } from "./abstractions.js";
|
|
2
|
-
export type { ISqlSchemaSetupRequest, SqlSchemaSetupRunParams } from "./abstractions.js";
|
|
2
|
+
export type { ISqlSchemaSetupRequest, ISqlSchemaSetupRequestOptions, SqlSchemaSetupRunParams } from "./abstractions.js";
|
|
3
|
+
export { runSqlSchemaSetups } from "./runSqlSchemaSetups.js";
|
|
4
|
+
export type { RunSqlSchemaSetupsParams, SqlSchemaSetupResult } from "./runSqlSchemaSetups.js";
|
|
3
5
|
export { runSchemaSetupSteps } from "./runSchemaSetupSteps.js";
|
|
4
6
|
export type { RequiredSqlSchemaSetup, RunSchemaSetupStepsParams } from "./runSchemaSetupSteps.js";
|
package/schemaSetup/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Knex } from "knex";
|
|
2
2
|
import type { Container } from "@webiny/feature/api";
|
|
3
|
+
import type { SqlDialect } from "../feature/SqlDialect/index.js";
|
|
4
|
+
import type { TenantStorageBackend } from "@webiny/api-core/features/tenancy/TenantStorages/abstractions.js";
|
|
3
5
|
import { type ISqlSchemaSetupRequest } from "./abstractions.js";
|
|
4
6
|
export interface RequiredSqlSchemaSetup {
|
|
5
7
|
/** The step's name (`SqlSchemaSetup.name`). */
|
|
@@ -12,11 +14,18 @@ export interface RunSchemaSetupStepsParams {
|
|
|
12
14
|
root: Container;
|
|
13
15
|
/** The setup's connection: a transaction the runner opened. */
|
|
14
16
|
knex: Knex;
|
|
17
|
+
/** The connection's database family. */
|
|
18
|
+
dialect: SqlDialect.Name;
|
|
15
19
|
tableNamePrefix?: string;
|
|
16
20
|
/** Registers a request's parts in the setup's container. */
|
|
17
21
|
request: ISqlSchemaSetupRequest;
|
|
18
22
|
/** Steps the storage can't run without (a module the project must add). */
|
|
19
23
|
required?: RequiredSqlSchemaSetup[];
|
|
24
|
+
/**
|
|
25
|
+
* An extra storage's backend, bound to the setup's connection: the request registers it instead
|
|
26
|
+
* of the default storage's, so the setup creates the tables of the parts a scope on it has.
|
|
27
|
+
*/
|
|
28
|
+
backend?: TenantStorageBackend.Interface;
|
|
20
29
|
}
|
|
21
30
|
/**
|
|
22
31
|
* The part of schema setup every SQL storage shares, run inside the runner's transaction. It builds
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { SqlConnectionFeature } from "../connection/SqlConnectionFeature.js";
|
|
2
2
|
import { SqlSchemaSetup } from "./abstractions.js";
|
|
3
3
|
async function runSchemaSetupSteps(params) {
|
|
4
|
-
const { root, knex, tableNamePrefix, request, required = [] } = params;
|
|
4
|
+
const { root, knex, dialect, tableNamePrefix, request, required = [], backend } = params;
|
|
5
5
|
const container = root.createChildContainer();
|
|
6
6
|
SqlConnectionFeature.register(container, {
|
|
7
7
|
knex,
|
|
8
|
+
dialect,
|
|
8
9
|
tableNamePrefix,
|
|
9
10
|
schemaManaged: false
|
|
10
11
|
});
|
|
11
|
-
await request.register(container
|
|
12
|
+
if (backend) await request.register(container, {
|
|
13
|
+
backend
|
|
14
|
+
});
|
|
15
|
+
else await request.register(container);
|
|
12
16
|
const steps = resolveSteps(container, required);
|
|
13
17
|
for (const step of required)if (!steps.some((item)=>item.name === step.name)) throw new Error(step.message);
|
|
14
18
|
const done = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaSetup/runSchemaSetupSteps.js","sources":["../../src/schemaSetup/runSchemaSetupSteps.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type { Container } from \"@webiny/feature/api\";\nimport { SqlConnectionFeature } from \"~/connection/SqlConnectionFeature.js\";\nimport { SqlSchemaSetup, type ISqlSchemaSetupRequest } from \"./abstractions.js\";\n\nexport interface RequiredSqlSchemaSetup {\n /** The step's name (`SqlSchemaSetup.name`). */\n name: string;\n /** The error when no step of that name is registered: what to add to the project. */\n message: string;\n}\n\nexport interface RunSchemaSetupStepsParams {\n /** The root container the storage is registered in. The setup's container is its child. */\n root: Container;\n /** The setup's connection: a transaction the runner opened. */\n knex: Knex;\n tableNamePrefix?: string;\n /** Registers a request's parts in the setup's container. */\n request: ISqlSchemaSetupRequest;\n /** Steps the storage can't run without (a module the project must add). */\n required?: RequiredSqlSchemaSetup[];\n}\n\n/**\n * The part of schema setup every SQL storage shares, run inside the runner's transaction. It builds\n * a container on the setup's connection the way a request's is built, and runs every schema setup\n * step in it.\n *\n * The container is a child of the root, so it has what a request has (the logger, the storages'\n * `RequestStorage`). The setup's connection is registered in it first, with schema-managed off:\n * every storage the request registers runs on it, including the ones built while the request\n * registers and the modules' singletons, which are built in the container that registers them.\n *\n * Checks `required` before running anything, so a missing module fails before any DDL. Returns the\n * names of the steps it ran, in order.\n */\nexport async function runSchemaSetupSteps(params: RunSchemaSetupStepsParams): Promise<string[]> {\n const { root, knex, tableNamePrefix, request, required = [] } = params;\n\n const container = root.createChildContainer();\n SqlConnectionFeature.register(container, {
|
|
1
|
+
{"version":3,"file":"schemaSetup/runSchemaSetupSteps.js","sources":["../../src/schemaSetup/runSchemaSetupSteps.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type { Container } from \"@webiny/feature/api\";\nimport { SqlConnectionFeature } from \"~/connection/SqlConnectionFeature.js\";\nimport type { SqlDialect } from \"~/feature/SqlDialect/index.js\";\nimport type { TenantStorageBackend } from \"@webiny/api-core/features/tenancy/TenantStorages/abstractions.js\";\nimport { SqlSchemaSetup, type ISqlSchemaSetupRequest } from \"./abstractions.js\";\n\nexport interface RequiredSqlSchemaSetup {\n /** The step's name (`SqlSchemaSetup.name`). */\n name: string;\n /** The error when no step of that name is registered: what to add to the project. */\n message: string;\n}\n\nexport interface RunSchemaSetupStepsParams {\n /** The root container the storage is registered in. The setup's container is its child. */\n root: Container;\n /** The setup's connection: a transaction the runner opened. */\n knex: Knex;\n /** The connection's database family. */\n dialect: SqlDialect.Name;\n tableNamePrefix?: string;\n /** Registers a request's parts in the setup's container. */\n request: ISqlSchemaSetupRequest;\n /** Steps the storage can't run without (a module the project must add). */\n required?: RequiredSqlSchemaSetup[];\n /**\n * An extra storage's backend, bound to the setup's connection: the request registers it instead\n * of the default storage's, so the setup creates the tables of the parts a scope on it has.\n */\n backend?: TenantStorageBackend.Interface;\n}\n\n/**\n * The part of schema setup every SQL storage shares, run inside the runner's transaction. It builds\n * a container on the setup's connection the way a request's is built, and runs every schema setup\n * step in it.\n *\n * The container is a child of the root, so it has what a request has (the logger, the storages'\n * `RequestStorage`). The setup's connection is registered in it first, with schema-managed off:\n * every storage the request registers runs on it, including the ones built while the request\n * registers and the modules' singletons, which are built in the container that registers them.\n *\n * Checks `required` before running anything, so a missing module fails before any DDL. Returns the\n * names of the steps it ran, in order.\n */\nexport async function runSchemaSetupSteps(params: RunSchemaSetupStepsParams): Promise<string[]> {\n const { root, knex, dialect, tableNamePrefix, request, required = [], backend } = params;\n\n const container = root.createChildContainer();\n SqlConnectionFeature.register(container, {\n knex,\n dialect,\n tableNamePrefix,\n schemaManaged: false\n });\n if (backend) {\n await request.register(container, { backend });\n } else {\n await request.register(container);\n }\n\n const steps = resolveSteps(container, required);\n for (const step of required) {\n if (!steps.some(item => item.name === step.name)) {\n throw new Error(step.message);\n }\n }\n\n const done: string[] = [];\n for (const step of steps) {\n await step.setup();\n done.push(step.name);\n }\n return done;\n}\n\n/**\n * Builds the steps. A step whose module needs another one that is missing (the folder catalog needs\n * the CMS's table names) can't be built, and that fails before any step has a name to check. So\n * the failure says which modules the storage needs, with the cause.\n */\nfunction resolveSteps(container: Container, required: RequiredSqlSchemaSetup[]) {\n try {\n return container.resolveAll(SqlSchemaSetup);\n } catch (error) {\n if (!required.length) {\n throw error;\n }\n const cause = error instanceof Error ? error.message : String(error);\n const needs = required.map(step => step.message).join(\" \");\n throw new Error(`Schema setup could not build its steps (${cause}). ${needs}`, {\n cause: error\n });\n }\n}\n"],"names":["runSchemaSetupSteps","params","root","knex","dialect","tableNamePrefix","request","required","backend","container","SqlConnectionFeature","steps","resolveSteps","step","item","Error","done","SqlSchemaSetup","error","cause","String","needs"],"mappings":";;AA8CO,eAAeA,oBAAoBC,MAAiC;IACvE,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAEC,eAAe,EAAEC,OAAO,EAAEC,WAAW,EAAE,EAAEC,OAAO,EAAE,GAAGP;IAElF,MAAMQ,YAAYP,KAAK,oBAAoB;IAC3CQ,qBAAqB,QAAQ,CAACD,WAAW;QACrCN;QACAC;QACAC;QACA,eAAe;IACnB;IACA,IAAIG,SACA,MAAMF,QAAQ,QAAQ,CAACG,WAAW;QAAED;IAAQ;SAE5C,MAAMF,QAAQ,QAAQ,CAACG;IAG3B,MAAME,QAAQC,aAAaH,WAAWF;IACtC,KAAK,MAAMM,QAAQN,SACf,IAAI,CAACI,MAAM,IAAI,CAACG,CAAAA,OAAQA,KAAK,IAAI,KAAKD,KAAK,IAAI,GAC3C,MAAM,IAAIE,MAAMF,KAAK,OAAO;IAIpC,MAAMG,OAAiB,EAAE;IACzB,KAAK,MAAMH,QAAQF,MAAO;QACtB,MAAME,KAAK,KAAK;QAChBG,KAAK,IAAI,CAACH,KAAK,IAAI;IACvB;IACA,OAAOG;AACX;AAOA,SAASJ,aAAaH,SAAoB,EAAEF,QAAkC;IAC1E,IAAI;QACA,OAAOE,UAAU,UAAU,CAACQ;IAChC,EAAE,OAAOC,OAAO;QACZ,IAAI,CAACX,SAAS,MAAM,EAChB,MAAMW;QAEV,MAAMC,QAAQD,iBAAiBH,QAAQG,MAAM,OAAO,GAAGE,OAAOF;QAC9D,MAAMG,QAAQd,SAAS,GAAG,CAACM,CAAAA,OAAQA,KAAK,OAAO,EAAE,IAAI,CAAC;QACtD,MAAM,IAAIE,MAAM,CAAC,wCAAwC,EAAEI,MAAM,GAAG,EAAEE,OAAO,EAAE;YAC3E,OAAOH;QACX;IACJ;AACJ"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Container } from "@webiny/feature/api";
|
|
2
|
+
import { type ISqlSchemaSetupRequest } from "./abstractions.js";
|
|
3
|
+
export interface RunSqlSchemaSetupsParams {
|
|
4
|
+
/** The root container the storages are registered in. */
|
|
5
|
+
root: Container;
|
|
6
|
+
/** Registers a request's parts in each setup's container. */
|
|
7
|
+
request: ISqlSchemaSetupRequest;
|
|
8
|
+
}
|
|
9
|
+
export interface SqlSchemaSetupResult {
|
|
10
|
+
/** The storage's id: `default`, or an extra storage's. */
|
|
11
|
+
storage: string;
|
|
12
|
+
/** The names of the steps its setup ran, in order. */
|
|
13
|
+
steps: string[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Runs the schema setup of every SQL storage registered in the root: the default storage first, then
|
|
17
|
+
* each extra one in the order it was registered. Each storage's runner opens its own transaction on
|
|
18
|
+
* its own connection (behind its own advisory lock on Postgres), so a storage's setup never waits for
|
|
19
|
+
* another's. The first failure stops the rest: a server must not start with a storage whose tables
|
|
20
|
+
* may be missing.
|
|
21
|
+
*/
|
|
22
|
+
export declare function runSqlSchemaSetups(params: RunSqlSchemaSetupsParams): Promise<SqlSchemaSetupResult[]>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TenantStorageId } from "@webiny/api-core/features/tenancy/TenantStorages/TenantStorageId.js";
|
|
2
|
+
import { SqlSchemaSetupRunner } from "./abstractions.js";
|
|
3
|
+
async function runSqlSchemaSetups(params) {
|
|
4
|
+
const runners = params.root.resolveAll(SqlSchemaSetupRunner);
|
|
5
|
+
const storageOf = (runner)=>TenantStorageId.from(runner.storage);
|
|
6
|
+
const ordered = [
|
|
7
|
+
...runners.filter((runner)=>storageOf(runner).isDefault()),
|
|
8
|
+
...runners.filter((runner)=>!storageOf(runner).isDefault())
|
|
9
|
+
];
|
|
10
|
+
const results = [];
|
|
11
|
+
for (const runner of ordered){
|
|
12
|
+
const steps = await runner.run({
|
|
13
|
+
request: params.request
|
|
14
|
+
});
|
|
15
|
+
results.push({
|
|
16
|
+
storage: storageOf(runner).toString(),
|
|
17
|
+
steps
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return results;
|
|
21
|
+
}
|
|
22
|
+
export { runSqlSchemaSetups };
|
|
23
|
+
|
|
24
|
+
//# sourceMappingURL=runSqlSchemaSetups.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaSetup/runSqlSchemaSetups.js","sources":["../../src/schemaSetup/runSqlSchemaSetups.ts"],"sourcesContent":["import type { Container } from \"@webiny/feature/api\";\nimport { TenantStorageId } from \"@webiny/api-core/features/tenancy/TenantStorages/TenantStorageId.js\";\nimport { SqlSchemaSetupRunner, type ISqlSchemaSetupRequest } from \"./abstractions.js\";\n\nexport interface RunSqlSchemaSetupsParams {\n /** The root container the storages are registered in. */\n root: Container;\n /** Registers a request's parts in each setup's container. */\n request: ISqlSchemaSetupRequest;\n}\n\nexport interface SqlSchemaSetupResult {\n /** The storage's id: `default`, or an extra storage's. */\n storage: string;\n /** The names of the steps its setup ran, in order. */\n steps: string[];\n}\n\n/**\n * Runs the schema setup of every SQL storage registered in the root: the default storage first, then\n * each extra one in the order it was registered. Each storage's runner opens its own transaction on\n * its own connection (behind its own advisory lock on Postgres), so a storage's setup never waits for\n * another's. The first failure stops the rest: a server must not start with a storage whose tables\n * may be missing.\n */\nexport async function runSqlSchemaSetups(\n params: RunSqlSchemaSetupsParams\n): Promise<SqlSchemaSetupResult[]> {\n const runners = params.root.resolveAll(SqlSchemaSetupRunner);\n const storageOf = (runner: SqlSchemaSetupRunner.Interface) => {\n return TenantStorageId.from(runner.storage);\n };\n const ordered = [\n ...runners.filter(runner => storageOf(runner).isDefault()),\n ...runners.filter(runner => !storageOf(runner).isDefault())\n ];\n\n const results: SqlSchemaSetupResult[] = [];\n for (const runner of ordered) {\n const steps = await runner.run({ request: params.request });\n results.push({ storage: storageOf(runner).toString(), steps });\n }\n return results;\n}\n"],"names":["runSqlSchemaSetups","params","runners","SqlSchemaSetupRunner","storageOf","runner","TenantStorageId","ordered","results","steps"],"mappings":";;AAyBO,eAAeA,mBAClBC,MAAgC;IAEhC,MAAMC,UAAUD,OAAO,IAAI,CAAC,UAAU,CAACE;IACvC,MAAMC,YAAY,CAACC,SACRC,gBAAgB,IAAI,CAACD,OAAO,OAAO;IAE9C,MAAME,UAAU;WACTL,QAAQ,MAAM,CAACG,CAAAA,SAAUD,UAAUC,QAAQ,SAAS;WACpDH,QAAQ,MAAM,CAACG,CAAAA,SAAU,CAACD,UAAUC,QAAQ,SAAS;KAC3D;IAED,MAAMG,UAAkC,EAAE;IAC1C,KAAK,MAAMH,UAAUE,QAAS;QAC1B,MAAME,QAAQ,MAAMJ,OAAO,GAAG,CAAC;YAAE,SAASJ,OAAO,OAAO;QAAC;QACzDO,QAAQ,IAAI,CAAC;YAAE,SAASJ,UAAUC,QAAQ,QAAQ;YAAII;QAAM;IAChE;IACA,OAAOD;AACX"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Container } from "@webiny/feature/api";
|
|
2
|
+
export interface ISqlScopeStorage {
|
|
3
|
+
/**
|
|
4
|
+
* Registers a part's storage in a tenant scope on a SQL storage, on the scope's connection and
|
|
5
|
+
* table settings (`KnexClient`, `SqlSchemaConfig`), which the storage registered first.
|
|
6
|
+
*/
|
|
7
|
+
register(container: Container): void | Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* A part of the API that keeps its data on whichever SQL storage a tenant runs on, added by the
|
|
11
|
+
* transport rather than by the storage: the standalone server's login (credentials, reset codes).
|
|
12
|
+
* Registered in the root, once per process. Every SQL storage, the default and each extra one,
|
|
13
|
+
* registers all of them in each tenant scope it serves, after its own storage parts. A scope on a
|
|
14
|
+
* storage that isn't SQL gets none.
|
|
15
|
+
*/
|
|
16
|
+
export declare const SqlScopeStorage: import("@webiny/di").Abstraction<ISqlScopeStorage>;
|
|
17
|
+
export declare namespace SqlScopeStorage {
|
|
18
|
+
type Interface = ISqlScopeStorage;
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopeStorage/abstractions.js","sources":["../../src/scopeStorage/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/api\";\nimport type { Container } from \"@webiny/feature/api\";\n\nexport interface ISqlScopeStorage {\n /**\n * Registers a part's storage in a tenant scope on a SQL storage, on the scope's connection and\n * table settings (`KnexClient`, `SqlSchemaConfig`), which the storage registered first.\n */\n register(container: Container): void | Promise<void>;\n}\n\n/**\n * A part of the API that keeps its data on whichever SQL storage a tenant runs on, added by the\n * transport rather than by the storage: the standalone server's login (credentials, reset codes).\n * Registered in the root, once per process. Every SQL storage, the default and each extra one,\n * registers all of them in each tenant scope it serves, after its own storage parts. A scope on a\n * storage that isn't SQL gets none.\n */\nexport const SqlScopeStorage = createAbstraction<ISqlScopeStorage>(\"Db/Sql/ScopeStorage\");\n\nexport namespace SqlScopeStorage {\n export type Interface = ISqlScopeStorage;\n}\n"],"names":["SqlScopeStorage","createAbstraction"],"mappings":";AAkBO,MAAMA,kBAAkBC,kBAAoC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Container } from "@webiny/feature/api";
|
|
2
|
+
/**
|
|
3
|
+
* Whether the container's SQL connection is Postgres: the connection of the tenant scope's storage,
|
|
4
|
+
* or of the schema setup the container was built for. `false` when the container has no SQL
|
|
5
|
+
* connection at all (a scope on DynamoDB).
|
|
6
|
+
*
|
|
7
|
+
* Reads the `SqlDialect` the storage registered with its connection. A scope on an extra storage
|
|
8
|
+
* registers its own over the default storage's in the root, and `resolve` returns the nearest.
|
|
9
|
+
*
|
|
10
|
+
* Modules that only run on Postgres (`<HeadlessCmsPg />`, `<AcoPg />`) come with the project's
|
|
11
|
+
* extensions, which register in every scope. A deploy whose default storage is SQLite or DynamoDB
|
|
12
|
+
* and that declares an extra Postgres storage registers them only where this is `true`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isPostgresScope(container: Container): boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SqlDialect } from "../feature/SqlDialect/index.js";
|
|
2
|
+
function isPostgresScope(container) {
|
|
3
|
+
if (0 === container.resolveAll(SqlDialect).length) return false;
|
|
4
|
+
return "postgres" === container.resolve(SqlDialect).name;
|
|
5
|
+
}
|
|
6
|
+
export { isPostgresScope };
|
|
7
|
+
|
|
8
|
+
//# sourceMappingURL=isPostgresScope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scopeStorage/isPostgresScope.js","sources":["../../src/scopeStorage/isPostgresScope.ts"],"sourcesContent":["import type { Container } from \"@webiny/feature/api\";\nimport { SqlDialect } from \"~/feature/SqlDialect/index.js\";\n\n/**\n * Whether the container's SQL connection is Postgres: the connection of the tenant scope's storage,\n * or of the schema setup the container was built for. `false` when the container has no SQL\n * connection at all (a scope on DynamoDB).\n *\n * Reads the `SqlDialect` the storage registered with its connection. A scope on an extra storage\n * registers its own over the default storage's in the root, and `resolve` returns the nearest.\n *\n * Modules that only run on Postgres (`<HeadlessCmsPg />`, `<AcoPg />`) come with the project's\n * extensions, which register in every scope. A deploy whose default storage is SQLite or DynamoDB\n * and that declares an extra Postgres storage registers them only where this is `true`.\n */\nexport function isPostgresScope(container: Container): boolean {\n if (container.resolveAll(SqlDialect).length === 0) {\n return false;\n }\n return container.resolve(SqlDialect).name === \"postgres\";\n}\n"],"names":["isPostgresScope","container","SqlDialect"],"mappings":";AAeO,SAASA,gBAAgBC,SAAoB;IAChD,IAAIA,AAA4C,MAA5CA,UAAU,UAAU,CAACC,YAAY,MAAM,EACvC,OAAO;IAEX,OAAOD,AAAuC,eAAvCA,UAAU,OAAO,CAACC,YAAY,IAAI;AAC7C"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Container } from "@webiny/feature/api";
|
|
2
|
+
import { RequestStorage } from "@webiny/api-core/features/requestStorage/abstractions.js";
|
|
3
|
+
import { TenantStorageBackend } from "@webiny/api-core/features/tenancy/TenantStorages/abstractions.js";
|
|
4
|
+
import { type SqlConnectionConfig } from "../connection/SqlConnectionFeature.js";
|
|
5
|
+
/** Which storage a SQL storage is: the deploy's default, or an extra one tenants can be placed on. */
|
|
6
|
+
export interface SqlStorageIdentityParams {
|
|
7
|
+
/**
|
|
8
|
+
* The storage's id. Left out (or `default`): the deploy's default storage, root's. Any other id
|
|
9
|
+
* makes it an extra storage, used only by the tenants whose `settings.storage` names it.
|
|
10
|
+
*/
|
|
11
|
+
id?: string;
|
|
12
|
+
/** How the storage is shown (the Tenant Manager's storage picker). Default: its family's name. */
|
|
13
|
+
label?: string;
|
|
14
|
+
/** No longer offered for new tenants; tenants already on it keep running there. */
|
|
15
|
+
retired?: boolean;
|
|
16
|
+
}
|
|
17
|
+
/** A storage's own parts of a tenant scope: core, audit logs, websockets, and so on. */
|
|
18
|
+
export type RegisterSqlStorageParts = (container: Container) => void | Promise<void>;
|
|
19
|
+
/** Registers the parts the transport adds to every SQL storage (`SqlScopeStorage`). */
|
|
20
|
+
export declare const registerSqlScopeStorages: (container: Container) => Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* The default SQL storage's part of a tenant scope (`RequestStorage`): its own parts, then the
|
|
23
|
+
* transport's. Its connection is in the root.
|
|
24
|
+
*/
|
|
25
|
+
export declare const createSqlRequestStorage: (registerParts: RegisterSqlStorageParts) => RequestStorage.Interface;
|
|
26
|
+
export interface CreateSqlTenantStorageBackendParams {
|
|
27
|
+
id: string;
|
|
28
|
+
label: string;
|
|
29
|
+
/** The storage's family: `postgres`, `sqlite`. */
|
|
30
|
+
type: string;
|
|
31
|
+
retired?: boolean;
|
|
32
|
+
/** The connection and its settings, registered in each scope on the storage. */
|
|
33
|
+
connection: SqlConnectionConfig;
|
|
34
|
+
registerParts: RegisterSqlStorageParts;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The backend of an extra SQL storage. A scope on it gets the storage's connection and settings
|
|
38
|
+
* first (`KnexClient`, `SqlSchemaConfig`), over the default storage's in the root, then the storage's
|
|
39
|
+
* parts and the transport's, all on that connection. Its tenant registry and global key-value store
|
|
40
|
+
* are root's, reached through root's scope (`TenantScopeRegistryFeature`).
|
|
41
|
+
*/
|
|
42
|
+
export declare const createSqlTenantStorageBackend: (params: CreateSqlTenantStorageBackendParams) => TenantStorageBackend.Interface;
|
|
43
|
+
/** Registers a storage's backend in the root, as a declared storage. */
|
|
44
|
+
export declare const registerTenantStorageBackend: (root: Container, backend: TenantStorageBackend.Interface) => void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { TenantStorageBackend } from "@webiny/api-core/features/tenancy/TenantStorages/abstractions.js";
|
|
2
|
+
import { SqlConnectionFeature } from "../connection/SqlConnectionFeature.js";
|
|
3
|
+
import { SqlScopeStorage } from "../scopeStorage/abstractions.js";
|
|
4
|
+
const registerSqlScopeStorages = async (container)=>{
|
|
5
|
+
for (const storage of container.resolveAll(SqlScopeStorage))await storage.register(container);
|
|
6
|
+
};
|
|
7
|
+
const createSqlRequestStorage = (registerParts)=>({
|
|
8
|
+
async register (container) {
|
|
9
|
+
await registerParts(container);
|
|
10
|
+
await registerSqlScopeStorages(container);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
const createSqlTenantStorageBackend = (params)=>{
|
|
14
|
+
const { id, label, type, retired, connection, registerParts } = params;
|
|
15
|
+
return {
|
|
16
|
+
id,
|
|
17
|
+
label,
|
|
18
|
+
type,
|
|
19
|
+
retired: true === retired,
|
|
20
|
+
async registerScope (container) {
|
|
21
|
+
SqlConnectionFeature.register(container, connection);
|
|
22
|
+
await registerParts(container);
|
|
23
|
+
await registerSqlScopeStorages(container);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const registerTenantStorageBackend = (root, backend)=>{
|
|
28
|
+
root.registerInstance(TenantStorageBackend, backend);
|
|
29
|
+
};
|
|
30
|
+
export { createSqlRequestStorage, createSqlTenantStorageBackend, registerSqlScopeStorages, registerTenantStorageBackend };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=sqlTenantStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage/sqlTenantStorage.js","sources":["../../src/storage/sqlTenantStorage.ts"],"sourcesContent":["import type { Container } from \"@webiny/feature/api\";\n// Deep imports: the package root pulls in all of api-core.\nimport { RequestStorage } from \"@webiny/api-core/features/requestStorage/abstractions.js\";\nimport { TenantStorageBackend } from \"@webiny/api-core/features/tenancy/TenantStorages/abstractions.js\";\nimport {\n SqlConnectionFeature,\n type SqlConnectionConfig\n} from \"~/connection/SqlConnectionFeature.js\";\nimport { SqlScopeStorage } from \"~/scopeStorage/abstractions.js\";\n\n/** Which storage a SQL storage is: the deploy's default, or an extra one tenants can be placed on. */\nexport interface SqlStorageIdentityParams {\n /**\n * The storage's id. Left out (or `default`): the deploy's default storage, root's. Any other id\n * makes it an extra storage, used only by the tenants whose `settings.storage` names it.\n */\n id?: string;\n /** How the storage is shown (the Tenant Manager's storage picker). Default: its family's name. */\n label?: string;\n /** No longer offered for new tenants; tenants already on it keep running there. */\n retired?: boolean;\n}\n\n/** A storage's own parts of a tenant scope: core, audit logs, websockets, and so on. */\nexport type RegisterSqlStorageParts = (container: Container) => void | Promise<void>;\n\n/** Registers the parts the transport adds to every SQL storage (`SqlScopeStorage`). */\nexport const registerSqlScopeStorages = async (container: Container): Promise<void> => {\n for (const storage of container.resolveAll(SqlScopeStorage)) {\n await storage.register(container);\n }\n};\n\n/**\n * The default SQL storage's part of a tenant scope (`RequestStorage`): its own parts, then the\n * transport's. Its connection is in the root.\n */\nexport const createSqlRequestStorage = (\n registerParts: RegisterSqlStorageParts\n): RequestStorage.Interface => {\n return {\n async register(container) {\n await registerParts(container);\n await registerSqlScopeStorages(container);\n }\n };\n};\n\nexport interface CreateSqlTenantStorageBackendParams {\n id: string;\n label: string;\n /** The storage's family: `postgres`, `sqlite`. */\n type: string;\n retired?: boolean;\n /** The connection and its settings, registered in each scope on the storage. */\n connection: SqlConnectionConfig;\n registerParts: RegisterSqlStorageParts;\n}\n\n/**\n * The backend of an extra SQL storage. A scope on it gets the storage's connection and settings\n * first (`KnexClient`, `SqlSchemaConfig`), over the default storage's in the root, then the storage's\n * parts and the transport's, all on that connection. Its tenant registry and global key-value store\n * are root's, reached through root's scope (`TenantScopeRegistryFeature`).\n */\nexport const createSqlTenantStorageBackend = (\n params: CreateSqlTenantStorageBackendParams\n): TenantStorageBackend.Interface => {\n const { id, label, type, retired, connection, registerParts } = params;\n return {\n id,\n label,\n type,\n retired: retired === true,\n async registerScope(container) {\n SqlConnectionFeature.register(container, connection);\n await registerParts(container);\n await registerSqlScopeStorages(container);\n }\n };\n};\n\n/** Registers a storage's backend in the root, as a declared storage. */\nexport const registerTenantStorageBackend = (\n root: Container,\n backend: TenantStorageBackend.Interface\n): void => {\n root.registerInstance(TenantStorageBackend, backend);\n};\n"],"names":["registerSqlScopeStorages","container","storage","SqlScopeStorage","createSqlRequestStorage","registerParts","createSqlTenantStorageBackend","params","id","label","type","retired","connection","SqlConnectionFeature","registerTenantStorageBackend","root","backend","TenantStorageBackend"],"mappings":";;;AA2BO,MAAMA,2BAA2B,OAAOC;IAC3C,KAAK,MAAMC,WAAWD,UAAU,UAAU,CAACE,iBACvC,MAAMD,QAAQ,QAAQ,CAACD;AAE/B;AAMO,MAAMG,0BAA0B,CACnCC,gBAEO;QACH,MAAM,UAASJ,SAAS;YACpB,MAAMI,cAAcJ;YACpB,MAAMD,yBAAyBC;QACnC;IACJ;AAoBG,MAAMK,gCAAgC,CACzCC;IAEA,MAAM,EAAEC,EAAE,EAAEC,KAAK,EAAEC,IAAI,EAAEC,OAAO,EAAEC,UAAU,EAAEP,aAAa,EAAE,GAAGE;IAChE,OAAO;QACHC;QACAC;QACAC;QACA,SAASC,AAAY,SAAZA;QACT,MAAM,eAAcV,SAAS;YACzBY,qBAAqB,QAAQ,CAACZ,WAAWW;YACzC,MAAMP,cAAcJ;YACpB,MAAMD,yBAAyBC;QACnC;IACJ;AACJ;AAGO,MAAMa,+BAA+B,CACxCC,MACAC;IAEAD,KAAK,gBAAgB,CAACE,sBAAsBD;AAChD"}
|
package/storage/types.d.ts
CHANGED
|
@@ -7,16 +7,25 @@ import type { Container } from "@webiny/feature/api";
|
|
|
7
7
|
* extensions.
|
|
8
8
|
*/
|
|
9
9
|
export interface SqlStorage {
|
|
10
|
+
/**
|
|
11
|
+
* The storage's id: `default` for the deploy's default storage (root's), any other for an extra
|
|
12
|
+
* storage that only the tenants naming it in `settings.storage` run on.
|
|
13
|
+
*/
|
|
14
|
+
readonly id: string;
|
|
10
15
|
/** The connection the storage runs on. */
|
|
11
16
|
readonly knex: Knex;
|
|
12
17
|
/** The prefix of every table the storage uses. */
|
|
13
18
|
readonly tableNamePrefix?: string;
|
|
14
19
|
/**
|
|
15
|
-
* Registers the storage in the transport's root container, once per process
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
+
* Registers the storage in the transport's root container, once per process, with its
|
|
21
|
+
* `SqlSchemaSetupRunner`. The transport runs the setups before the API takes traffic
|
|
22
|
+
* (`runSqlSchemaSetups`); once a storage's ran, it is schema-managed: no part checks for or
|
|
23
|
+
* creates tables at runtime.
|
|
24
|
+
*
|
|
25
|
+
* The default storage registers its connection and settings (`SqlConnectionFeature`) and a
|
|
26
|
+
* `RequestStorage` that registers its parts (core, audit logs, websockets) in each scope on the
|
|
27
|
+
* default storage. An extra storage registers a `TenantStorageBackend` instead, which registers
|
|
28
|
+
* its connection, settings and parts in each scope on it; the root holds none of them.
|
|
20
29
|
*/
|
|
21
30
|
register(container: Container): void;
|
|
22
31
|
}
|
package/tenancy/index.js
CHANGED
|
@@ -1,27 +1,58 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { TenantPath } from "@webiny/api-core/features/tenancy/shared/TenantPath.js";
|
|
2
|
+
import _webiny_error from "@webiny/error";
|
|
2
3
|
const TABLE_NAME = "webiny_core_tenants";
|
|
3
4
|
const tenantToRow = (tenant)=>({
|
|
4
5
|
id: tenant.id,
|
|
5
6
|
parent: tenant.parent,
|
|
7
|
+
path: TenantPath.fromStored(tenant).toString(),
|
|
6
8
|
createdOn: tenant.createdOn,
|
|
7
9
|
data: JSON.stringify(tenant)
|
|
8
10
|
});
|
|
11
|
+
const escapeLike = (value)=>value.replace(/[\\%_]/g, (character)=>`\\${character}`);
|
|
9
12
|
const rowToTenant = (row)=>{
|
|
10
13
|
const tenant = JSON.parse(row.data);
|
|
11
14
|
if (!tenant.tags) tenant.tags = [];
|
|
12
15
|
if (!tenant.description) tenant.description = "";
|
|
16
|
+
tenant.path = TenantPath.fromStored(tenant).toString();
|
|
13
17
|
return tenant;
|
|
14
18
|
};
|
|
19
|
+
const addPathColumnIfMissing = async (knex, tableName)=>{
|
|
20
|
+
if (await knex.schema.hasColumn(tableName, "path")) return;
|
|
21
|
+
if ("postgresql" === knex.client.dialect) return void await knex.raw("ALTER TABLE ?? ADD COLUMN IF NOT EXISTS ?? text", [
|
|
22
|
+
tableName,
|
|
23
|
+
"path"
|
|
24
|
+
]);
|
|
25
|
+
try {
|
|
26
|
+
await knex.schema.alterTable(tableName, (table)=>{
|
|
27
|
+
table.text("path");
|
|
28
|
+
});
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (await knex.schema.hasColumn(tableName, "path")) return;
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const backfillMissingPaths = async (knex, tableName)=>{
|
|
35
|
+
await knex.transaction(async (trx)=>{
|
|
36
|
+
const rows = await trx(tableName).whereNull("path").select("*");
|
|
37
|
+
for (const row of rows)await trx(tableName).where("id", row.id).whereNull("path").update({
|
|
38
|
+
path: rowToTenant(row).path
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
};
|
|
15
42
|
const createStorageOperations = (params)=>{
|
|
16
43
|
const { knex, tableManager } = params;
|
|
17
44
|
const ensureTable = tableManager.define(TABLE_NAME, (table)=>{
|
|
18
45
|
table.text("id").primary().notNullable();
|
|
19
46
|
table.text("parent");
|
|
47
|
+
table.text("path");
|
|
20
48
|
table.text("createdOn").notNullable();
|
|
21
49
|
table.text("data").notNullable();
|
|
22
50
|
table.index([
|
|
23
51
|
"parent"
|
|
24
52
|
]);
|
|
53
|
+
}, async (knex, tableName)=>{
|
|
54
|
+
await addPathColumnIfMissing(knex, tableName);
|
|
55
|
+
await backfillMissingPaths(knex, tableName);
|
|
25
56
|
});
|
|
26
57
|
const query = ()=>knex(tableManager.resolve(TABLE_NAME));
|
|
27
58
|
return {
|
|
@@ -31,7 +62,7 @@ const createStorageOperations = (params)=>{
|
|
|
31
62
|
const rows = await query().whereIn("id", ids);
|
|
32
63
|
return rows.map(rowToTenant);
|
|
33
64
|
} catch (err) {
|
|
34
|
-
throw
|
|
65
|
+
throw _webiny_error.from(err, {
|
|
35
66
|
message: "Could not get tenants by IDs.",
|
|
36
67
|
code: "GET_TENANTS_BY_IDS_ERROR",
|
|
37
68
|
data: {
|
|
@@ -44,12 +75,23 @@ const createStorageOperations = (params)=>{
|
|
|
44
75
|
await ensureTable();
|
|
45
76
|
try {
|
|
46
77
|
const qb = query();
|
|
47
|
-
|
|
78
|
+
const { parent, descendants } = params;
|
|
79
|
+
const ancestor = parent && descendants ? parent.path : null;
|
|
80
|
+
if (ancestor) {
|
|
81
|
+
const prefix = escapeLike(ancestor.descendantsPrefix());
|
|
82
|
+
qb.whereRaw("?? LIKE ? ESCAPE ?", [
|
|
83
|
+
"path",
|
|
84
|
+
`${prefix}%`,
|
|
85
|
+
"\\"
|
|
86
|
+
]);
|
|
87
|
+
} else if (parent) qb.where("parent", parent.id);
|
|
48
88
|
qb.orderBy("createdOn", "asc");
|
|
49
89
|
const rows = await qb;
|
|
50
|
-
|
|
90
|
+
const tenants = rows.map(rowToTenant);
|
|
91
|
+
if (!ancestor) return tenants;
|
|
92
|
+
return tenants.filter((tenant)=>TenantPath.fromStored(tenant).isDescendantOf(ancestor));
|
|
51
93
|
} catch (err) {
|
|
52
|
-
throw
|
|
94
|
+
throw _webiny_error.from(err, {
|
|
53
95
|
message: "Could not list tenants.",
|
|
54
96
|
code: "LIST_TENANTS_ERROR",
|
|
55
97
|
data: {
|
|
@@ -65,7 +107,7 @@ const createStorageOperations = (params)=>{
|
|
|
65
107
|
await query().insert(row);
|
|
66
108
|
return data;
|
|
67
109
|
} catch (err) {
|
|
68
|
-
throw
|
|
110
|
+
throw _webiny_error.from(err, {
|
|
69
111
|
message: "Could not create tenant record.",
|
|
70
112
|
code: "CREATE_TENANT_ERROR",
|
|
71
113
|
data: {
|
|
@@ -81,7 +123,7 @@ const createStorageOperations = (params)=>{
|
|
|
81
123
|
await query().where("id", data.id).update(row);
|
|
82
124
|
return data;
|
|
83
125
|
} catch (err) {
|
|
84
|
-
throw
|
|
126
|
+
throw _webiny_error.from(err, {
|
|
85
127
|
message: "Could not update tenant record.",
|
|
86
128
|
code: "UPDATE_TENANT_ERROR",
|
|
87
129
|
data: {
|
|
@@ -95,7 +137,7 @@ const createStorageOperations = (params)=>{
|
|
|
95
137
|
try {
|
|
96
138
|
await query().where("id", id).delete();
|
|
97
139
|
} catch (err) {
|
|
98
|
-
throw
|
|
140
|
+
throw _webiny_error.from(err, {
|
|
99
141
|
message: "Could not delete tenant record.",
|
|
100
142
|
code: "DELETE_TENANT_ERROR",
|
|
101
143
|
data: {
|
package/tenancy/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tenancy/index.js","sources":["../../src/tenancy/index.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type {\n ListTenantsParams,\n TenancyStorageOperations,\n Tenant\n} from \"@webiny/api-core/types/tenancy.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { TableManager } from \"~/TableManager.js\";\n\nconst TABLE_NAME = \"webiny_core_tenants\";\n\ninterface ITenantRow {\n id: string;\n parent: string | null;\n createdOn: string;\n data: string;\n}\n\nconst tenantToRow = (tenant: Tenant): ITenantRow => {\n return {\n id: tenant.id,\n parent: tenant.parent,\n createdOn: tenant.createdOn,\n data: JSON.stringify(tenant)\n };\n};\n\nconst rowToTenant = (row: ITenantRow): Tenant => {\n const tenant = JSON.parse(row.data) as Tenant;\n\n if (!tenant.tags) {\n tenant.tags = [];\n }\n\n if (!tenant.description) {\n tenant.description = \"\";\n }\n\n return tenant;\n};\n\ninterface CreateStorageOperationsParams {\n knex: Knex;\n tableManager: TableManager;\n}\n\nexport const createStorageOperations = (\n params: CreateStorageOperationsParams\n): TenancyStorageOperations => {\n const { knex, tableManager } = params;\n\n const ensureTable = tableManager.define(TABLE_NAME, table => {\n table.text(\"id\").primary().notNullable();\n table.text(\"parent\");\n table.text(\"createdOn\").notNullable();\n table.text(\"data\").notNullable();\n\n table.index([\"parent\"]);\n });\n\n const query = () => {\n return knex<ITenantRow>(tableManager.resolve(TABLE_NAME));\n };\n\n return {\n async getTenantsByIds(ids: readonly string[]): Promise<Tenant[]> {\n await ensureTable();\n\n try {\n const rows = await query().whereIn(\"id\", ids);\n\n return rows.map(rowToTenant);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not get tenants by IDs.\",\n code: \"GET_TENANTS_BY_IDS_ERROR\",\n data: {\n ids\n }\n });\n }\n },\n\n async listTenants(params: ListTenantsParams = {}): Promise<Tenant[]> {\n await ensureTable();\n\n try {\n const qb = query();\n\n if (params.parent) {\n qb.where(\"parent\", params.parent);\n }\n\n qb.orderBy(\"createdOn\", \"asc\");\n\n const rows = await qb;\n\n return rows.map(rowToTenant);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list tenants.\",\n code: \"LIST_TENANTS_ERROR\",\n data: { params }\n });\n }\n },\n\n async createTenant(data: Tenant): Promise<Tenant> {\n await ensureTable();\n\n try {\n const row = tenantToRow(data);\n await query().insert(row);\n\n return data;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create tenant record.\",\n code: \"CREATE_TENANT_ERROR\",\n data: { tenant: data }\n });\n }\n },\n\n async updateTenant(data: Tenant): Promise<Tenant> {\n await ensureTable();\n\n try {\n const row = tenantToRow(data);\n await query().where(\"id\", data.id).update(row);\n\n return data;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update tenant record.\",\n code: \"UPDATE_TENANT_ERROR\",\n data: { tenant: data }\n });\n }\n },\n\n async deleteTenant(id: string): Promise<void> {\n await ensureTable();\n\n try {\n await query().where(\"id\", id).delete();\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete tenant record.\",\n code: \"DELETE_TENANT_ERROR\",\n data: { id }\n });\n }\n }\n };\n};\n"],"names":["TABLE_NAME","tenantToRow","tenant","JSON","rowToTenant","row","createStorageOperations","params","knex","tableManager","ensureTable","table","query","ids","rows","err","WebinyError","qb","data","id"],"mappings":";AASA,MAAMA,aAAa;AASnB,MAAMC,cAAc,CAACC,SACV;QACH,IAAIA,OAAO,EAAE;QACb,QAAQA,OAAO,MAAM;QACrB,WAAWA,OAAO,SAAS;QAC3B,MAAMC,KAAK,SAAS,CAACD;IACzB;AAGJ,MAAME,cAAc,CAACC;IACjB,MAAMH,SAASC,KAAK,KAAK,CAACE,IAAI,IAAI;IAElC,IAAI,CAACH,OAAO,IAAI,EACZA,OAAO,IAAI,GAAG,EAAE;IAGpB,IAAI,CAACA,OAAO,WAAW,EACnBA,OAAO,WAAW,GAAG;IAGzB,OAAOA;AACX;AAOO,MAAMI,0BAA0B,CACnCC;IAEA,MAAM,EAAEC,IAAI,EAAEC,YAAY,EAAE,GAAGF;IAE/B,MAAMG,cAAcD,aAAa,MAAM,CAACT,YAAYW,CAAAA;QAChDA,MAAM,IAAI,CAAC,MAAM,OAAO,GAAG,WAAW;QACtCA,MAAM,IAAI,CAAC;QACXA,MAAM,IAAI,CAAC,aAAa,WAAW;QACnCA,MAAM,IAAI,CAAC,QAAQ,WAAW;QAE9BA,MAAM,KAAK,CAAC;YAAC;SAAS;IAC1B;IAEA,MAAMC,QAAQ,IACHJ,KAAiBC,aAAa,OAAO,CAACT;IAGjD,OAAO;QACH,MAAM,iBAAgBa,GAAsB;YACxC,MAAMH;YAEN,IAAI;gBACA,MAAMI,OAAO,MAAMF,QAAQ,OAAO,CAAC,MAAMC;gBAEzC,OAAOC,KAAK,GAAG,CAACV;YACpB,EAAE,OAAOW,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBACFF;oBACJ;gBACJ;YACJ;QACJ;QAEA,MAAM,aAAYN,SAA4B,CAAC,CAAC;YAC5C,MAAMG;YAEN,IAAI;gBACA,MAAMO,KAAKL;gBAEX,IAAIL,OAAO,MAAM,EACbU,GAAG,KAAK,CAAC,UAAUV,OAAO,MAAM;gBAGpCU,GAAG,OAAO,CAAC,aAAa;gBAExB,MAAMH,OAAO,MAAMG;gBAEnB,OAAOH,KAAK,GAAG,CAACV;YACpB,EAAE,OAAOW,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAER;oBAAO;gBACnB;YACJ;QACJ;QAEA,MAAM,cAAaW,IAAY;YAC3B,MAAMR;YAEN,IAAI;gBACA,MAAML,MAAMJ,YAAYiB;gBACxB,MAAMN,QAAQ,MAAM,CAACP;gBAErB,OAAOa;YACX,EAAE,OAAOH,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAE,QAAQG;oBAAK;gBACzB;YACJ;QACJ;QAEA,MAAM,cAAaA,IAAY;YAC3B,MAAMR;YAEN,IAAI;gBACA,MAAML,MAAMJ,YAAYiB;gBACxB,MAAMN,QAAQ,KAAK,CAAC,MAAMM,KAAK,EAAE,EAAE,MAAM,CAACb;gBAE1C,OAAOa;YACX,EAAE,OAAOH,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAE,QAAQG;oBAAK;gBACzB;YACJ;QACJ;QAEA,MAAM,cAAaC,EAAU;YACzB,MAAMT;YAEN,IAAI;gBACA,MAAME,QAAQ,KAAK,CAAC,MAAMO,IAAI,MAAM;YACxC,EAAE,OAAOJ,KAAK;gBACV,MAAMC,MAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAEI;oBAAG;gBACf;YACJ;QACJ;IACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"tenancy/index.js","sources":["../../src/tenancy/index.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type {\n ListTenantsStorageParams,\n TenancyStorageOperations,\n Tenant\n} from \"@webiny/api-core/types/tenancy.js\";\nimport { TenantPath } from \"@webiny/api-core/features/tenancy/shared/TenantPath.js\";\nimport WebinyError from \"@webiny/error\";\nimport type { TableManager } from \"~/TableManager.js\";\n\nconst TABLE_NAME = \"webiny_core_tenants\";\n\ninterface ITenantRow {\n id: string;\n parent: string | null;\n path: string | null;\n createdOn: string;\n data: string;\n}\n\nconst tenantToRow = (tenant: Tenant): ITenantRow => {\n return {\n id: tenant.id,\n parent: tenant.parent,\n path: TenantPath.fromStored(tenant).toString(),\n createdOn: tenant.createdOn,\n data: JSON.stringify(tenant)\n };\n};\n\n/* `LIKE` treats `%` and `_` as wildcards, and ids may contain `_`: match them literally. */\nconst escapeLike = (value: string) => value.replace(/[\\\\%_]/g, character => `\\\\${character}`);\n\nconst rowToTenant = (row: ITenantRow): Tenant => {\n const tenant = JSON.parse(row.data) as Tenant;\n\n if (!tenant.tags) {\n tenant.tags = [];\n }\n\n if (!tenant.description) {\n tenant.description = \"\";\n }\n\n tenant.path = TenantPath.fromStored(tenant).toString();\n return tenant;\n};\n\nconst addPathColumnIfMissing = async (knex: Knex, tableName: string): Promise<void> => {\n if (await knex.schema.hasColumn(tableName, \"path\")) {\n return;\n }\n if (knex.client.dialect === \"postgresql\") {\n /* A failed statement would abort a surrounding transaction: don't fail on a race. */\n await knex.raw(\"ALTER TABLE ?? ADD COLUMN IF NOT EXISTS ?? text\", [tableName, \"path\"]);\n return;\n }\n try {\n await knex.schema.alterTable(tableName, table => {\n table.text(\"path\");\n });\n } catch (error) {\n // Another process added it between the check and the alter.\n if (await knex.schema.hasColumn(tableName, \"path\")) {\n return;\n }\n throw error;\n }\n};\n\n/* Rows written since the column exists always have a path: only older rows are filled in. */\nconst backfillMissingPaths = async (knex: Knex, tableName: string): Promise<void> => {\n await knex.transaction(async trx => {\n const rows: ITenantRow[] = await trx(tableName).whereNull(\"path\").select(\"*\");\n for (const row of rows) {\n await trx(tableName)\n .where(\"id\", row.id)\n .whereNull(\"path\")\n .update({ path: rowToTenant(row).path });\n }\n });\n};\n\ninterface CreateStorageOperationsParams {\n knex: Knex;\n tableManager: TableManager;\n}\n\nexport const createStorageOperations = (\n params: CreateStorageOperationsParams\n): TenancyStorageOperations => {\n const { knex, tableManager } = params;\n\n const ensureTable = tableManager.define(\n TABLE_NAME,\n table => {\n table.text(\"id\").primary().notNullable();\n table.text(\"parent\");\n table.text(\"path\");\n table.text(\"createdOn\").notNullable();\n table.text(\"data\").notNullable();\n\n table.index([\"parent\"]);\n },\n /*\n * A table created before tenant paths existed (a local dev database) gets the column, and\n * its rows their paths, which are all derived from `parent` (see `TenantPath.fromStored`).\n * Both steps are re-runnable: a start that died between them, or a second process adding\n * the column at the same time, leaves nothing the next start doesn't finish.\n */\n async (knex, tableName) => {\n await addPathColumnIfMissing(knex, tableName);\n await backfillMissingPaths(knex, tableName);\n }\n );\n\n const query = () => {\n return knex<ITenantRow>(tableManager.resolve(TABLE_NAME));\n };\n\n return {\n async getTenantsByIds(ids: readonly string[]): Promise<Tenant[]> {\n await ensureTable();\n\n try {\n const rows = await query().whereIn(\"id\", ids);\n\n return rows.map(rowToTenant);\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not get tenants by IDs.\",\n code: \"GET_TENANTS_BY_IDS_ERROR\",\n data: {\n ids\n }\n });\n }\n },\n\n async listTenants(params: ListTenantsStorageParams = {}): Promise<Tenant[]> {\n await ensureTable();\n\n try {\n const qb = query();\n const { parent, descendants } = params;\n const ancestor = parent && descendants ? parent.path : null;\n\n if (ancestor) {\n const prefix = escapeLike(ancestor.descendantsPrefix());\n qb.whereRaw(\"?? LIKE ? ESCAPE ?\", [\"path\", `${prefix}%`, \"\\\\\"]);\n } else if (parent) {\n qb.where(\"parent\", parent.id);\n }\n\n qb.orderBy(\"createdOn\", \"asc\");\n\n const rows = await qb;\n const tenants = rows.map(rowToTenant);\n if (!ancestor) {\n return tenants;\n }\n /* SQLite's LIKE ignores case: `root/a/x` must not count as one of `root/A`'s. */\n return tenants.filter(tenant => {\n return TenantPath.fromStored(tenant).isDescendantOf(ancestor);\n });\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not list tenants.\",\n code: \"LIST_TENANTS_ERROR\",\n data: { params }\n });\n }\n },\n\n async createTenant(data: Tenant): Promise<Tenant> {\n await ensureTable();\n\n try {\n const row = tenantToRow(data);\n await query().insert(row);\n\n return data;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not create tenant record.\",\n code: \"CREATE_TENANT_ERROR\",\n data: { tenant: data }\n });\n }\n },\n\n async updateTenant(data: Tenant): Promise<Tenant> {\n await ensureTable();\n\n try {\n const row = tenantToRow(data);\n await query().where(\"id\", data.id).update(row);\n\n return data;\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not update tenant record.\",\n code: \"UPDATE_TENANT_ERROR\",\n data: { tenant: data }\n });\n }\n },\n\n async deleteTenant(id: string): Promise<void> {\n await ensureTable();\n\n try {\n await query().where(\"id\", id).delete();\n } catch (err) {\n throw WebinyError.from(err, {\n message: \"Could not delete tenant record.\",\n code: \"DELETE_TENANT_ERROR\",\n data: { id }\n });\n }\n }\n };\n};\n"],"names":["TABLE_NAME","tenantToRow","tenant","TenantPath","JSON","escapeLike","value","character","rowToTenant","row","addPathColumnIfMissing","knex","tableName","table","error","backfillMissingPaths","trx","rows","createStorageOperations","params","tableManager","ensureTable","query","ids","err","WebinyError","qb","parent","descendants","ancestor","prefix","tenants","data","id"],"mappings":";;AAUA,MAAMA,aAAa;AAUnB,MAAMC,cAAc,CAACC,SACV;QACH,IAAIA,OAAO,EAAE;QACb,QAAQA,OAAO,MAAM;QACrB,MAAMC,WAAW,UAAU,CAACD,QAAQ,QAAQ;QAC5C,WAAWA,OAAO,SAAS;QAC3B,MAAME,KAAK,SAAS,CAACF;IACzB;AAIJ,MAAMG,aAAa,CAACC,QAAkBA,MAAM,OAAO,CAAC,WAAWC,CAAAA,YAAa,CAAC,EAAE,EAAEA,WAAW;AAE5F,MAAMC,cAAc,CAACC;IACjB,MAAMP,SAASE,KAAK,KAAK,CAACK,IAAI,IAAI;IAElC,IAAI,CAACP,OAAO,IAAI,EACZA,OAAO,IAAI,GAAG,EAAE;IAGpB,IAAI,CAACA,OAAO,WAAW,EACnBA,OAAO,WAAW,GAAG;IAGzBA,OAAO,IAAI,GAAGC,WAAW,UAAU,CAACD,QAAQ,QAAQ;IACpD,OAAOA;AACX;AAEA,MAAMQ,yBAAyB,OAAOC,MAAYC;IAC9C,IAAI,MAAMD,KAAK,MAAM,CAAC,SAAS,CAACC,WAAW,SACvC;IAEJ,IAAID,AAAwB,iBAAxBA,KAAK,MAAM,CAAC,OAAO,EAAmB,YAEtC,MAAMA,KAAK,GAAG,CAAC,mDAAmD;QAACC;QAAW;KAAO;IAGzF,IAAI;QACA,MAAMD,KAAK,MAAM,CAAC,UAAU,CAACC,WAAWC,CAAAA;YACpCA,MAAM,IAAI,CAAC;QACf;IACJ,EAAE,OAAOC,OAAO;QAEZ,IAAI,MAAMH,KAAK,MAAM,CAAC,SAAS,CAACC,WAAW,SACvC;QAEJ,MAAME;IACV;AACJ;AAGA,MAAMC,uBAAuB,OAAOJ,MAAYC;IAC5C,MAAMD,KAAK,WAAW,CAAC,OAAMK;QACzB,MAAMC,OAAqB,MAAMD,IAAIJ,WAAW,SAAS,CAAC,QAAQ,MAAM,CAAC;QACzE,KAAK,MAAMH,OAAOQ,KACd,MAAMD,IAAIJ,WACL,KAAK,CAAC,MAAMH,IAAI,EAAE,EAClB,SAAS,CAAC,QACV,MAAM,CAAC;YAAE,MAAMD,YAAYC,KAAK,IAAI;QAAC;IAElD;AACJ;AAOO,MAAMS,0BAA0B,CACnCC;IAEA,MAAM,EAAER,IAAI,EAAES,YAAY,EAAE,GAAGD;IAE/B,MAAME,cAAcD,aAAa,MAAM,CACnCpB,YACAa,CAAAA;QACIA,MAAM,IAAI,CAAC,MAAM,OAAO,GAAG,WAAW;QACtCA,MAAM,IAAI,CAAC;QACXA,MAAM,IAAI,CAAC;QACXA,MAAM,IAAI,CAAC,aAAa,WAAW;QACnCA,MAAM,IAAI,CAAC,QAAQ,WAAW;QAE9BA,MAAM,KAAK,CAAC;YAAC;SAAS;IAC1B,GAOA,OAAOF,MAAMC;QACT,MAAMF,uBAAuBC,MAAMC;QACnC,MAAMG,qBAAqBJ,MAAMC;IACrC;IAGJ,MAAMU,QAAQ,IACHX,KAAiBS,aAAa,OAAO,CAACpB;IAGjD,OAAO;QACH,MAAM,iBAAgBuB,GAAsB;YACxC,MAAMF;YAEN,IAAI;gBACA,MAAMJ,OAAO,MAAMK,QAAQ,OAAO,CAAC,MAAMC;gBAEzC,OAAON,KAAK,GAAG,CAACT;YACpB,EAAE,OAAOgB,KAAK;gBACV,MAAMC,cAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBACFD;oBACJ;gBACJ;YACJ;QACJ;QAEA,MAAM,aAAYJ,SAAmC,CAAC,CAAC;YACnD,MAAME;YAEN,IAAI;gBACA,MAAMK,KAAKJ;gBACX,MAAM,EAAEK,MAAM,EAAEC,WAAW,EAAE,GAAGT;gBAChC,MAAMU,WAAWF,UAAUC,cAAcD,OAAO,IAAI,GAAG;gBAEvD,IAAIE,UAAU;oBACV,MAAMC,SAASzB,WAAWwB,SAAS,iBAAiB;oBACpDH,GAAG,QAAQ,CAAC,sBAAsB;wBAAC;wBAAQ,GAAGI,OAAO,CAAC,CAAC;wBAAE;qBAAK;gBAClE,OAAO,IAAIH,QACPD,GAAG,KAAK,CAAC,UAAUC,OAAO,EAAE;gBAGhCD,GAAG,OAAO,CAAC,aAAa;gBAExB,MAAMT,OAAO,MAAMS;gBACnB,MAAMK,UAAUd,KAAK,GAAG,CAACT;gBACzB,IAAI,CAACqB,UACD,OAAOE;gBAGX,OAAOA,QAAQ,MAAM,CAAC7B,CAAAA,SACXC,WAAW,UAAU,CAACD,QAAQ,cAAc,CAAC2B;YAE5D,EAAE,OAAOL,KAAK;gBACV,MAAMC,cAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAEL;oBAAO;gBACnB;YACJ;QACJ;QAEA,MAAM,cAAaa,IAAY;YAC3B,MAAMX;YAEN,IAAI;gBACA,MAAMZ,MAAMR,YAAY+B;gBACxB,MAAMV,QAAQ,MAAM,CAACb;gBAErB,OAAOuB;YACX,EAAE,OAAOR,KAAK;gBACV,MAAMC,cAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAE,QAAQQ;oBAAK;gBACzB;YACJ;QACJ;QAEA,MAAM,cAAaA,IAAY;YAC3B,MAAMX;YAEN,IAAI;gBACA,MAAMZ,MAAMR,YAAY+B;gBACxB,MAAMV,QAAQ,KAAK,CAAC,MAAMU,KAAK,EAAE,EAAE,MAAM,CAACvB;gBAE1C,OAAOuB;YACX,EAAE,OAAOR,KAAK;gBACV,MAAMC,cAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAE,QAAQQ;oBAAK;gBACzB;YACJ;QACJ;QAEA,MAAM,cAAaC,EAAU;YACzB,MAAMZ;YAEN,IAAI;gBACA,MAAMC,QAAQ,KAAK,CAAC,MAAMW,IAAI,MAAM;YACxC,EAAE,OAAOT,KAAK;gBACV,MAAMC,cAAAA,IAAgB,CAACD,KAAK;oBACxB,SAAS;oBACT,MAAM;oBACN,MAAM;wBAAES;oBAAG;gBACf;YACJ;QACJ;IACJ;AACJ"}
|