@webiny/api-core-sql 6.6.0-alpha.10 → 6.6.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/TableManager.d.ts +23 -20
- package/TableManager.js +22 -35
- package/TableManager.js.map +1 -1
- package/connection/SqlConnectionFeature.d.ts +28 -0
- package/connection/SqlConnectionFeature.js +26 -0
- package/connection/SqlConnectionFeature.js.map +1 -0
- package/connection/index.d.ts +2 -0
- package/connection/index.js +1 -0
- package/coreStorage/CoreSqlSchemaSetup.d.ts +18 -0
- package/coreStorage/CoreSqlSchemaSetup.js +35 -0
- package/coreStorage/CoreSqlSchemaSetup.js.map +1 -0
- package/coreStorage/SqlApiCoreStorageOperationsFactory.d.ts +15 -0
- package/coreStorage/SqlApiCoreStorageOperationsFactory.js +32 -0
- package/coreStorage/SqlApiCoreStorageOperationsFactory.js.map +1 -0
- package/coreStorage/feature.d.ts +13 -0
- package/coreStorage/feature.js +13 -0
- package/coreStorage/feature.js.map +1 -0
- package/coreStorage/index.d.ts +1 -0
- package/coreStorage/index.js +1 -0
- package/createApiCoreSql.d.ts +13 -1
- package/createApiCoreSql.js +8 -8
- package/createApiCoreSql.js.map +1 -1
- package/index.d.ts +14 -4
- package/index.js +8 -3
- package/index.js.map +1 -1
- package/package.json +6 -6
- package/schemaConfig/abstractions.d.ts +22 -0
- package/schemaConfig/abstractions.js +5 -0
- package/schemaConfig/abstractions.js.map +1 -0
- package/schemaConfig/index.d.ts +1 -0
- package/schemaConfig/index.js +1 -0
- package/schemaMemory/ensureTable.d.ts +28 -0
- package/schemaMemory/ensureTable.js +43 -0
- package/schemaMemory/ensureTable.js.map +1 -0
- package/schemaMemory/getConnectionKey.d.ts +8 -0
- package/schemaMemory/getConnectionKey.js +15 -0
- package/schemaMemory/getConnectionKey.js.map +1 -0
- package/schemaMemory/getSchemaMemory.d.ts +37 -0
- package/schemaMemory/getSchemaMemory.js +53 -0
- package/schemaMemory/getSchemaMemory.js.map +1 -0
- package/schemaSetup/abstractions.d.ts +67 -0
- package/schemaSetup/abstractions.js +6 -0
- package/schemaSetup/abstractions.js.map +1 -0
- package/schemaSetup/index.d.ts +4 -0
- package/schemaSetup/index.js +2 -0
- package/schemaSetup/runSchemaSetupSteps.d.ts +34 -0
- package/schemaSetup/runSchemaSetupSteps.js +35 -0
- package/schemaSetup/runSchemaSetupSteps.js.map +1 -0
- package/serviceDiscovery/SqlServiceManifestLoader.js +3 -6
- package/serviceDiscovery/SqlServiceManifestLoader.js.map +1 -1
- package/serviceDiscovery/SqlServiceManifestWriter.d.ts +16 -0
- package/serviceDiscovery/SqlServiceManifestWriter.js +27 -0
- package/serviceDiscovery/SqlServiceManifestWriter.js.map +1 -0
- package/serviceDiscovery/index.d.ts +1 -0
- package/serviceDiscovery/index.js +1 -0
- package/serviceDiscovery/serviceManifestsTable.d.ts +13 -0
- package/serviceDiscovery/serviceManifestsTable.js +8 -0
- package/serviceDiscovery/serviceManifestsTable.js.map +1 -0
- package/storage/types.d.ts +22 -0
- package/storage/types.js +0 -0
- package/ApiCoreSqlFeature.d.ts +0 -18
- package/ApiCoreSqlFeature.js +0 -18
- package/ApiCoreSqlFeature.js.map +0 -1
- package/schemaManaged.d.ts +0 -8
- package/schemaManaged.js +0 -4
- package/schemaManaged.js.map +0 -1
package/TableManager.d.ts
CHANGED
|
@@ -1,33 +1,36 @@
|
|
|
1
1
|
import type { Knex } from "knex";
|
|
2
|
-
type TableCreator
|
|
3
|
-
interface
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { type TableCreator } from "./schemaMemory/ensureTable.js";
|
|
3
|
+
export interface TableManagerOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The schema was set up before the API took traffic (see `SqlSchemaConfig`): `ensure()` then
|
|
6
|
+
* never checks for or creates a table. `setup()` still creates them. A function when it can
|
|
7
|
+
* change (a server turns it on once its schema setup at start ran): read on every `ensure()`.
|
|
8
|
+
*/
|
|
9
|
+
schemaManaged?: boolean | (() => boolean);
|
|
7
10
|
}
|
|
8
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The tables of one SQL storage part (core, audit logs, login) on one connection. Built wherever the
|
|
13
|
+
* storage is built, which is once per request: it holds no state of its own. What it learns (which
|
|
14
|
+
* tables exist) is kept for the process, in one memory per connection and table prefix, so a new
|
|
15
|
+
* instance doesn't check a table again and a long-running server keeps one entry per connection, not
|
|
16
|
+
* one per request.
|
|
17
|
+
*/
|
|
18
|
+
export declare class TableManager {
|
|
9
19
|
private readonly knex;
|
|
10
20
|
private readonly prefix;
|
|
11
|
-
private readonly
|
|
12
|
-
private readonly pending;
|
|
21
|
+
private readonly schemaManaged;
|
|
13
22
|
private readonly defined;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* schema setup builds the storage operations (which declare their tables), then calls this.
|
|
18
|
-
* Managers of other knex instances (an earlier setup in a warm process) are left alone.
|
|
19
|
-
*/
|
|
20
|
-
static setupAll(knex: Knex): Promise<void>;
|
|
23
|
+
private memoryOfTables?;
|
|
24
|
+
constructor(knex: Knex, prefix?: string, options?: TableManagerOptions);
|
|
25
|
+
/** Forgets which tables this connection has (test setups drop all tables between tests). */
|
|
21
26
|
reset(): void;
|
|
22
27
|
/**
|
|
23
28
|
* Declares a table and returns the function that ensures it on first use. Declared tables are
|
|
24
|
-
* created together by `setup()` (
|
|
29
|
+
* created together by `setup()` (schema setup).
|
|
25
30
|
*/
|
|
26
31
|
define(tableName: string, creator: TableCreator): () => Promise<void>;
|
|
27
32
|
setup(): Promise<void>;
|
|
28
33
|
resolve(tableName: string): string;
|
|
29
|
-
ensure(tableName: string, creator:
|
|
30
|
-
private
|
|
31
|
-
private createTable;
|
|
34
|
+
ensure(tableName: string, creator: TableCreator): Promise<void>;
|
|
35
|
+
private get memory();
|
|
32
36
|
}
|
|
33
|
-
export {};
|
package/TableManager.js
CHANGED
|
@@ -1,57 +1,44 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getSchemaMemory } from "./schemaMemory/getSchemaMemory.js";
|
|
2
|
+
import { getConnectionKey } from "./schemaMemory/getConnectionKey.js";
|
|
3
|
+
import { createTableIfMissing, ensureTable, recordTable } from "./schemaMemory/ensureTable.js";
|
|
2
4
|
class TableManager {
|
|
3
|
-
constructor(knex, prefix = ""){
|
|
4
|
-
this.verified = new Set();
|
|
5
|
-
this.pending = new Map();
|
|
5
|
+
constructor(knex, prefix = "", options = {}){
|
|
6
6
|
this.defined = new Map();
|
|
7
7
|
this.knex = knex;
|
|
8
8
|
this.prefix = prefix ? `${prefix}_` : "";
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
managers.push(this);
|
|
12
|
-
}
|
|
13
|
-
static async setupAll(knex) {
|
|
14
|
-
const managers = globalThis.__sqlTableManagers ?? [];
|
|
15
|
-
for (const manager of managers)if (manager instanceof TableManager && manager.knex === knex) await manager.setup();
|
|
9
|
+
const schemaManaged = options.schemaManaged;
|
|
10
|
+
this.schemaManaged = "function" == typeof schemaManaged ? schemaManaged : ()=>true === schemaManaged;
|
|
16
11
|
}
|
|
17
12
|
reset() {
|
|
18
|
-
this.
|
|
19
|
-
this.pending.clear();
|
|
13
|
+
this.memory.reset();
|
|
20
14
|
}
|
|
21
15
|
define(tableName, creator) {
|
|
22
16
|
this.defined.set(tableName, creator);
|
|
23
17
|
return ()=>this.ensure(tableName, creator);
|
|
24
18
|
}
|
|
25
19
|
async setup() {
|
|
26
|
-
for (const [tableName, creator] of this.defined)
|
|
20
|
+
for (const [tableName, creator] of this.defined){
|
|
21
|
+
const resolved = this.resolve(tableName);
|
|
22
|
+
const generation = this.memory.generation;
|
|
23
|
+
await createTableIfMissing(this.knex, resolved, creator);
|
|
24
|
+
if (this.memory.generation === generation) recordTable(this.knex, this.memory, resolved);
|
|
25
|
+
}
|
|
27
26
|
}
|
|
28
27
|
resolve(tableName) {
|
|
29
28
|
return `${this.prefix}${tableName}`;
|
|
30
29
|
}
|
|
31
30
|
async ensure(tableName, creator) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
if (this.schemaManaged()) return;
|
|
32
|
+
await ensureTable({
|
|
33
|
+
knex: this.knex,
|
|
34
|
+
memory: this.memory,
|
|
35
|
+
tableName: this.resolve(tableName),
|
|
36
|
+
create: creator
|
|
38
37
|
});
|
|
39
|
-
this.pending.set(resolved, check);
|
|
40
|
-
return check;
|
|
41
38
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
this.verified.add(resolved);
|
|
46
|
-
}
|
|
47
|
-
async createTable(resolved, creator) {
|
|
48
|
-
try {
|
|
49
|
-
await this.knex.schema.createTable(resolved, creator);
|
|
50
|
-
} catch (err) {
|
|
51
|
-
const exists = await this.knex.schema.hasTable(resolved);
|
|
52
|
-
if (exists) return;
|
|
53
|
-
throw err;
|
|
54
|
-
}
|
|
39
|
+
get memory() {
|
|
40
|
+
this.memoryOfTables ??= getSchemaMemory(`core.sql.tables:${getConnectionKey(this.knex)}:${this.prefix}`);
|
|
41
|
+
return this.memoryOfTables;
|
|
55
42
|
}
|
|
56
43
|
}
|
|
57
44
|
export { TableManager };
|
package/TableManager.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableManager.js","sources":["../src/TableManager.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport {
|
|
1
|
+
{"version":3,"file":"TableManager.js","sources":["../src/TableManager.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport { getSchemaMemory, type ISchemaMemory } from \"./schemaMemory/getSchemaMemory.js\";\nimport { getConnectionKey } from \"./schemaMemory/getConnectionKey.js\";\nimport {\n createTableIfMissing,\n ensureTable,\n recordTable,\n type TableCreator\n} from \"./schemaMemory/ensureTable.js\";\n\nexport interface TableManagerOptions {\n /**\n * The schema was set up before the API took traffic (see `SqlSchemaConfig`): `ensure()` then\n * never checks for or creates a table. `setup()` still creates them. A function when it can\n * change (a server turns it on once its schema setup at start ran): read on every `ensure()`.\n */\n schemaManaged?: boolean | (() => boolean);\n}\n\n/**\n * The tables of one SQL storage part (core, audit logs, login) on one connection. Built wherever the\n * storage is built, which is once per request: it holds no state of its own. What it learns (which\n * tables exist) is kept for the process, in one memory per connection and table prefix, so a new\n * instance doesn't check a table again and a long-running server keeps one entry per connection, not\n * one per request.\n */\nexport class TableManager {\n private readonly knex: Knex;\n private readonly prefix: string;\n private readonly schemaManaged: () => boolean;\n /* Tables declared by the storage operations using this manager, for schema setup. */\n private readonly defined = new Map<string, TableCreator>();\n private memoryOfTables?: ISchemaMemory;\n\n constructor(knex: Knex, prefix: string = \"\", options: TableManagerOptions = {}) {\n this.knex = knex;\n this.prefix = prefix ? `${prefix}_` : \"\";\n const schemaManaged = options.schemaManaged;\n this.schemaManaged =\n typeof schemaManaged === \"function\" ? schemaManaged : () => schemaManaged === true;\n }\n\n /** Forgets which tables this connection has (test setups drop all tables between tests). */\n public reset(): void {\n this.memory.reset();\n }\n\n /**\n * Declares a table and returns the function that ensures it on first use. Declared tables are\n * created together by `setup()` (schema setup).\n */\n public define(tableName: string, creator: TableCreator): () => Promise<void> {\n this.defined.set(tableName, creator);\n return () => this.ensure(tableName, creator);\n }\n\n /* Creates every declared table that doesn't exist yet. Runs at schema setup. */\n public async setup(): Promise<void> {\n for (const [tableName, creator] of this.defined) {\n const resolved = this.resolve(tableName);\n // Nothing checked before a reset is recorded after it (as in `ensureTable`).\n const generation = this.memory.generation;\n await createTableIfMissing(this.knex, resolved, creator);\n if (this.memory.generation === generation) {\n recordTable(this.knex, this.memory, resolved);\n }\n }\n }\n\n public resolve(tableName: string): string {\n return `${this.prefix}${tableName}`;\n }\n\n public async ensure(tableName: string, creator: TableCreator): Promise<void> {\n if (this.schemaManaged()) {\n return;\n }\n await ensureTable({\n knex: this.knex,\n memory: this.memory,\n tableName: this.resolve(tableName),\n create: creator\n });\n }\n\n /* Made on first use: a schema-managed manager never needs it. */\n private get memory(): ISchemaMemory {\n this.memoryOfTables ??= getSchemaMemory(\n `core.sql.tables:${getConnectionKey(this.knex)}:${this.prefix}`\n );\n return this.memoryOfTables;\n }\n}\n"],"names":["TableManager","knex","prefix","options","Map","schemaManaged","tableName","creator","resolved","generation","createTableIfMissing","recordTable","ensureTable","getSchemaMemory","getConnectionKey"],"mappings":";;;AA0BO,MAAMA;IAQT,YAAYC,IAAU,EAAEC,SAAiB,EAAE,EAAEC,UAA+B,CAAC,CAAC,CAAE;QAJG,KAClE,OAAO,GAAG,IAAIC;QAI3B,IAAI,CAAC,IAAI,GAAGH;QACZ,IAAI,CAAC,MAAM,GAAGC,SAAS,GAAGA,OAAO,CAAC,CAAC,GAAG;QACtC,MAAMG,gBAAgBF,QAAQ,aAAa;QAC3C,IAAI,CAAC,aAAa,GACd,AAAyB,cAAzB,OAAOE,gBAA+BA,gBAAgB,IAAMA,AAAkB,SAAlBA;IACpE;IAGO,QAAc;QACjB,IAAI,CAAC,MAAM,CAAC,KAAK;IACrB;IAMO,OAAOC,SAAiB,EAAEC,OAAqB,EAAuB;QACzE,IAAI,CAAC,OAAO,CAAC,GAAG,CAACD,WAAWC;QAC5B,OAAO,IAAM,IAAI,CAAC,MAAM,CAACD,WAAWC;IACxC;IAGA,MAAa,QAAuB;QAChC,KAAK,MAAM,CAACD,WAAWC,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAE;YAC7C,MAAMC,WAAW,IAAI,CAAC,OAAO,CAACF;YAE9B,MAAMG,aAAa,IAAI,CAAC,MAAM,CAAC,UAAU;YACzC,MAAMC,qBAAqB,IAAI,CAAC,IAAI,EAAEF,UAAUD;YAChD,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,KAAKE,YAC3BE,YAAY,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAEH;QAE5C;IACJ;IAEO,QAAQF,SAAiB,EAAU;QACtC,OAAO,GAAG,IAAI,CAAC,MAAM,GAAGA,WAAW;IACvC;IAEA,MAAa,OAAOA,SAAiB,EAAEC,OAAqB,EAAiB;QACzE,IAAI,IAAI,CAAC,aAAa,IAClB;QAEJ,MAAMK,YAAY;YACd,MAAM,IAAI,CAAC,IAAI;YACf,QAAQ,IAAI,CAAC,MAAM;YACnB,WAAW,IAAI,CAAC,OAAO,CAACN;YACxB,QAAQC;QACZ;IACJ;IAGA,IAAY,SAAwB;QAChC,IAAI,CAAC,cAAc,KAAKM,gBACpB,CAAC,gBAAgB,EAAEC,iBAAiB,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE;QAEnE,OAAO,IAAI,CAAC,cAAc;IAC9B;AACJ"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Knex } from "knex";
|
|
2
|
+
export interface SqlConnectionConfig {
|
|
3
|
+
knex: Knex;
|
|
4
|
+
tableNamePrefix?: string;
|
|
5
|
+
/**
|
|
6
|
+
* The schema was set up before the API took traffic (the storage's schema setup ran), so no
|
|
7
|
+
* storage code checks for or creates tables at runtime. Off by default: tables are created on
|
|
8
|
+
* first use. A function when it can change: a server turns it on once its setup at start ran.
|
|
9
|
+
*/
|
|
10
|
+
schemaManaged?: boolean | (() => boolean);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* What a SQL storage puts in the root container, once per process: the connection (`KnexClient`)
|
|
14
|
+
* and its settings, the table prefix and the schema-managed setting (`SqlSchemaConfig`). Every
|
|
15
|
+
* storage part registered per request, and every module on the storage (the Postgres CMS, the folder
|
|
16
|
+
* catalog), runs on these.
|
|
17
|
+
*
|
|
18
|
+
* It holds no feature's storage: those register per request (`RequestStorage`).
|
|
19
|
+
*/
|
|
20
|
+
export declare const SqlConnectionFeature: {
|
|
21
|
+
name: string;
|
|
22
|
+
register(container: import("@webiny/di").Container, context: SqlConnectionConfig): void;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Points service discovery at the manifests table of a connection. The loader is a static global of
|
|
26
|
+
* the process, not a DI registration, so a storage sets it once, when it registers in the root.
|
|
27
|
+
*/
|
|
28
|
+
export declare const setSqlServiceManifestLoader: (config: SqlConnectionConfig) => void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { ServiceDiscovery } from "@webiny/api-core/features/serviceDiscovery/index.js";
|
|
3
|
+
import { KnexClientFeature } from "../feature/KnexClient/index.js";
|
|
4
|
+
import { SqlSchemaConfig } from "../schemaConfig/index.js";
|
|
5
|
+
import { SqlServiceManifestLoader } from "../serviceDiscovery/index.js";
|
|
6
|
+
import { TableManager } from "../TableManager.js";
|
|
7
|
+
const isManaged = (schemaManaged)=>"function" == typeof schemaManaged ? schemaManaged() : true === schemaManaged;
|
|
8
|
+
const SqlConnectionFeature = createFeature({
|
|
9
|
+
name: "SqlConnection",
|
|
10
|
+
register (container, { knex, tableNamePrefix, schemaManaged = false }) {
|
|
11
|
+
KnexClientFeature.register(container, knex);
|
|
12
|
+
container.registerInstance(SqlSchemaConfig, {
|
|
13
|
+
isManaged: ()=>isManaged(schemaManaged),
|
|
14
|
+
tableNamePrefix
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const setSqlServiceManifestLoader = (config)=>{
|
|
19
|
+
const tableManager = new TableManager(config.knex, config.tableNamePrefix, {
|
|
20
|
+
schemaManaged: ()=>isManaged(config.schemaManaged)
|
|
21
|
+
});
|
|
22
|
+
ServiceDiscovery.setLoader(new SqlServiceManifestLoader(config.knex, tableManager));
|
|
23
|
+
};
|
|
24
|
+
export { SqlConnectionFeature, setSqlServiceManifestLoader };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=SqlConnectionFeature.js.map
|
|
@@ -0,0 +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 { SqlSchemaConfig } from \"~/schemaConfig/index.js\";\nimport { SqlServiceManifestLoader } from \"~/serviceDiscovery/index.js\";\nimport { TableManager } from \"~/TableManager.js\";\n\nexport interface SqlConnectionConfig {\n knex: Knex;\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 * What a SQL storage puts in the root container, once per process: the connection (`KnexClient`)\n * and its settings, the table prefix and the schema-managed setting (`SqlSchemaConfig`). Every\n * storage part registered per request, and every module on the storage (the Postgres CMS, the folder\n * catalog), runs on these.\n *\n * It holds no feature's storage: those register per request (`RequestStorage`).\n */\nexport const SqlConnectionFeature = createFeature<SqlConnectionConfig>({\n name: \"SqlConnection\",\n register(container, { knex, tableNamePrefix, schemaManaged = false }) {\n KnexClientFeature.register(container, knex);\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: SqlConnectionConfig): 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","tableNamePrefix","KnexClientFeature","SqlSchemaConfig","setSqlServiceManifestLoader","config","tableManager","TableManager","ServiceDiscovery","SqlServiceManifestLoader"],"mappings":";;;;;;AAmBA,MAAMA,YAAY,CAACC,gBACR,AAAyB,cAAzB,OAAOA,gBAA+BA,kBAAkBA,AAAkB,SAAlBA;AAW5D,MAAMC,uBAAuBC,cAAmC;IACnE,MAAM;IACN,UAASC,SAAS,EAAE,EAAEC,IAAI,EAAEC,eAAe,EAAEL,gBAAgB,KAAK,EAAE;QAChEM,kBAAkB,QAAQ,CAACH,WAAWC;QACtCD,UAAU,gBAAgB,CAACI,iBAAiB;YACxC,WAAW,IAAMR,UAAUC;YAC3BK;QACJ;IACJ;AACJ;AAMO,MAAMG,8BAA8B,CAACC;IACxC,MAAMC,eAAe,IAAIC,aAAaF,OAAO,IAAI,EAAEA,OAAO,eAAe,EAAE;QACvE,eAAe,IAAMV,UAAUU,OAAO,aAAa;IACvD;IACAG,iBAAiB,SAAS,CAAC,IAAIC,yBAAyBJ,OAAO,IAAI,EAAEC;AACzE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SqlConnectionFeature, setSqlServiceManifestLoader } from "./SqlConnectionFeature.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { KnexClient } from "../feature/KnexClient/index.js";
|
|
2
|
+
import { SqlSchemaConfig } from "../schemaConfig/index.js";
|
|
3
|
+
import { SqlSchemaSetup } from "../schemaSetup/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* The `core` schema setup step: the tables of users, tenancy, security, the key-value store and the
|
|
6
|
+
* service manifests, on the container's connection.
|
|
7
|
+
*/
|
|
8
|
+
declare class CoreSqlSchemaSetupImpl implements SqlSchemaSetup.Interface {
|
|
9
|
+
private readonly knex;
|
|
10
|
+
private readonly schemaConfig?;
|
|
11
|
+
readonly name = "core";
|
|
12
|
+
constructor(knex: KnexClient.Interface, schemaConfig?: SqlSchemaConfig.Interface | undefined);
|
|
13
|
+
setup(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
export declare const CoreSqlSchemaSetup: typeof CoreSqlSchemaSetupImpl & {
|
|
16
|
+
__abstraction: import("@webiny/di").Abstraction<import("../schemaSetup/abstractions").ISqlSchemaSetup>;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { createApiCoreSqlOperations } from "../createApiCoreSql.js";
|
|
2
|
+
import { KnexClient } from "../feature/KnexClient/index.js";
|
|
3
|
+
import { SqlSchemaConfig } from "../schemaConfig/index.js";
|
|
4
|
+
import { SqlSchemaSetup } from "../schemaSetup/index.js";
|
|
5
|
+
import { TableManager } from "../TableManager.js";
|
|
6
|
+
import { defineServiceManifestsTable } from "../serviceDiscovery/serviceManifestsTable.js";
|
|
7
|
+
class CoreSqlSchemaSetupImpl {
|
|
8
|
+
constructor(knex, schemaConfig){
|
|
9
|
+
this.knex = knex;
|
|
10
|
+
this.schemaConfig = schemaConfig;
|
|
11
|
+
this.name = "core";
|
|
12
|
+
}
|
|
13
|
+
async setup() {
|
|
14
|
+
const knex = this.knex.client;
|
|
15
|
+
const tableManager = new TableManager(knex, this.schemaConfig?.tableNamePrefix);
|
|
16
|
+
createApiCoreSqlOperations(knex, tableManager);
|
|
17
|
+
defineServiceManifestsTable(tableManager);
|
|
18
|
+
await tableManager.setup();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const CoreSqlSchemaSetup = SqlSchemaSetup.createImplementation({
|
|
22
|
+
implementation: CoreSqlSchemaSetupImpl,
|
|
23
|
+
dependencies: [
|
|
24
|
+
KnexClient,
|
|
25
|
+
[
|
|
26
|
+
SqlSchemaConfig,
|
|
27
|
+
{
|
|
28
|
+
optional: true
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
]
|
|
32
|
+
});
|
|
33
|
+
export { CoreSqlSchemaSetup };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=CoreSqlSchemaSetup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coreStorage/CoreSqlSchemaSetup.js","sources":["../../src/coreStorage/CoreSqlSchemaSetup.ts"],"sourcesContent":["import { createApiCoreSqlOperations } from \"~/createApiCoreSql.js\";\nimport { KnexClient } from \"~/feature/KnexClient/index.js\";\nimport { SqlSchemaConfig } from \"~/schemaConfig/index.js\";\nimport { SqlSchemaSetup } from \"~/schemaSetup/index.js\";\nimport { TableManager } from \"~/TableManager.js\";\nimport { defineServiceManifestsTable } from \"~/serviceDiscovery/serviceManifestsTable.js\";\n\n/**\n * The `core` schema setup step: the tables of users, tenancy, security, the key-value store and the\n * service manifests, on the container's connection.\n */\nclass CoreSqlSchemaSetupImpl implements SqlSchemaSetup.Interface {\n public readonly name = \"core\";\n\n public constructor(\n private readonly knex: KnexClient.Interface,\n private readonly schemaConfig?: SqlSchemaConfig.Interface\n ) {}\n\n public async setup(): Promise<void> {\n const knex = this.knex.client;\n const tableManager = new TableManager(knex, this.schemaConfig?.tableNamePrefix);\n // Building them declares their tables on the manager.\n createApiCoreSqlOperations(knex, tableManager);\n defineServiceManifestsTable(tableManager);\n await tableManager.setup();\n }\n}\n\nexport const CoreSqlSchemaSetup = SqlSchemaSetup.createImplementation({\n implementation: CoreSqlSchemaSetupImpl,\n dependencies: [KnexClient, [SqlSchemaConfig, { optional: true }]]\n});\n"],"names":["CoreSqlSchemaSetupImpl","knex","schemaConfig","tableManager","TableManager","createApiCoreSqlOperations","defineServiceManifestsTable","CoreSqlSchemaSetup","SqlSchemaSetup","KnexClient","SqlSchemaConfig"],"mappings":";;;;;;AAWA,MAAMA;IAGF,YACqBC,IAA0B,EAC1BC,YAAwC,CAC3D;aAFmBD,IAAI,GAAJA;aACAC,YAAY,GAAZA;aAJL,IAAI,GAAG;IAKpB;IAEH,MAAa,QAAuB;QAChC,MAAMD,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM;QAC7B,MAAME,eAAe,IAAIC,aAAaH,MAAM,IAAI,CAAC,YAAY,EAAE;QAE/DI,2BAA2BJ,MAAME;QACjCG,4BAA4BH;QAC5B,MAAMA,aAAa,KAAK;IAC5B;AACJ;AAEO,MAAMI,qBAAqBC,eAAe,oBAAoB,CAAC;IAClE,gBAAgBR;IAChB,cAAc;QAACS;QAAY;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ApiCoreStorageOperationsFactory } from "@webiny/api-core";
|
|
2
|
+
import type { ApiCoreStorageOperations } from "@webiny/api-core/types/core.js";
|
|
3
|
+
import { KnexClient } from "../feature/KnexClient/index.js";
|
|
4
|
+
import { SqlSchemaConfig } from "../schemaConfig/index.js";
|
|
5
|
+
/** Builds the core storage operations on the container's connection and table prefix. */
|
|
6
|
+
declare class SqlApiCoreStorageOperationsFactoryImpl implements ApiCoreStorageOperationsFactory.Interface {
|
|
7
|
+
private readonly knex;
|
|
8
|
+
private readonly schemaConfig?;
|
|
9
|
+
constructor(knex: KnexClient.Interface, schemaConfig?: SqlSchemaConfig.Interface | undefined);
|
|
10
|
+
create(): ApiCoreStorageOperations;
|
|
11
|
+
}
|
|
12
|
+
export declare const SqlApiCoreStorageOperationsFactory: typeof SqlApiCoreStorageOperationsFactoryImpl & {
|
|
13
|
+
__abstraction: import("@webiny/di").Abstraction<import("@webiny/api-core/features/storageOperations/abstractions").IApiCoreStorageOperationsFactory>;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ApiCoreStorageOperationsFactory } from "@webiny/api-core";
|
|
2
|
+
import { createApiCoreSql } from "../createApiCoreSql.js";
|
|
3
|
+
import { KnexClient } from "../feature/KnexClient/index.js";
|
|
4
|
+
import { SqlSchemaConfig } from "../schemaConfig/index.js";
|
|
5
|
+
class SqlApiCoreStorageOperationsFactoryImpl {
|
|
6
|
+
constructor(knex, schemaConfig){
|
|
7
|
+
this.knex = knex;
|
|
8
|
+
this.schemaConfig = schemaConfig;
|
|
9
|
+
}
|
|
10
|
+
create() {
|
|
11
|
+
return createApiCoreSql({
|
|
12
|
+
knex: this.knex.client,
|
|
13
|
+
tableNamePrefix: this.schemaConfig?.tableNamePrefix,
|
|
14
|
+
schemaManaged: this.schemaConfig?.isManaged() === true
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const SqlApiCoreStorageOperationsFactory = ApiCoreStorageOperationsFactory.createImplementation({
|
|
19
|
+
implementation: SqlApiCoreStorageOperationsFactoryImpl,
|
|
20
|
+
dependencies: [
|
|
21
|
+
KnexClient,
|
|
22
|
+
[
|
|
23
|
+
SqlSchemaConfig,
|
|
24
|
+
{
|
|
25
|
+
optional: true
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
]
|
|
29
|
+
});
|
|
30
|
+
export { SqlApiCoreStorageOperationsFactory };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=SqlApiCoreStorageOperationsFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coreStorage/SqlApiCoreStorageOperationsFactory.js","sources":["../../src/coreStorage/SqlApiCoreStorageOperationsFactory.ts"],"sourcesContent":["import { ApiCoreStorageOperationsFactory } from \"@webiny/api-core\";\nimport type { ApiCoreStorageOperations } from \"@webiny/api-core/types/core.js\";\nimport { createApiCoreSql } from \"~/createApiCoreSql.js\";\nimport { KnexClient } from \"~/feature/KnexClient/index.js\";\nimport { SqlSchemaConfig } from \"~/schemaConfig/index.js\";\n\n/** Builds the core storage operations on the container's connection and table prefix. */\nclass SqlApiCoreStorageOperationsFactoryImpl implements ApiCoreStorageOperationsFactory.Interface {\n public constructor(\n private readonly knex: KnexClient.Interface,\n private readonly schemaConfig?: SqlSchemaConfig.Interface\n ) {}\n\n public create(): ApiCoreStorageOperations {\n return createApiCoreSql({\n knex: this.knex.client,\n tableNamePrefix: this.schemaConfig?.tableNamePrefix,\n schemaManaged: this.schemaConfig?.isManaged() === true\n });\n }\n}\n\nexport const SqlApiCoreStorageOperationsFactory =\n ApiCoreStorageOperationsFactory.createImplementation({\n implementation: SqlApiCoreStorageOperationsFactoryImpl,\n dependencies: [KnexClient, [SqlSchemaConfig, { optional: true }]]\n });\n"],"names":["SqlApiCoreStorageOperationsFactoryImpl","knex","schemaConfig","createApiCoreSql","SqlApiCoreStorageOperationsFactory","ApiCoreStorageOperationsFactory","KnexClient","SqlSchemaConfig"],"mappings":";;;;AAOA,MAAMA;IACF,YACqBC,IAA0B,EAC1BC,YAAwC,CAC3D;aAFmBD,IAAI,GAAJA;aACAC,YAAY,GAAZA;IAClB;IAEI,SAAmC;QACtC,OAAOC,iBAAiB;YACpB,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM;YACtB,iBAAiB,IAAI,CAAC,YAAY,EAAE;YACpC,eAAe,IAAI,CAAC,YAAY,EAAE,gBAAgB;QACtD;IACJ;AACJ;AAEO,MAAMC,qCACTC,gCAAgC,oBAAoB,CAAC;IACjD,gBAAgBL;IAChB,cAAc;QAACM;QAAY;YAACC;YAAiB;gBAAE,UAAU;YAAK;SAAE;KAAC;AACrE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The SQL core storage of a request: the implementation of `ApiCoreStorageOperationsFactory`, which
|
|
3
|
+
* `ApiCoreFeature.register` resolves and builds, and the `core` schema setup step. Mirrors
|
|
4
|
+
* `ApiCoreDdbFeature`.
|
|
5
|
+
*
|
|
6
|
+
* Registered per request (by the SQL storage's `RequestStorage`). It runs on what the root holds:
|
|
7
|
+
* the connection (`KnexClient`) and the table prefix and schema-managed setting (`SqlSchemaConfig`),
|
|
8
|
+
* both registered by `SqlConnectionFeature`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ApiCoreSqlFeature: {
|
|
11
|
+
name: string;
|
|
12
|
+
register(container: import("@webiny/di").Container): void;
|
|
13
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createFeature } from "@webiny/feature/api";
|
|
2
|
+
import { SqlApiCoreStorageOperationsFactory } from "./SqlApiCoreStorageOperationsFactory.js";
|
|
3
|
+
import { CoreSqlSchemaSetup } from "./CoreSqlSchemaSetup.js";
|
|
4
|
+
const ApiCoreSqlFeature = createFeature({
|
|
5
|
+
name: "ApiCoreSql",
|
|
6
|
+
register (container) {
|
|
7
|
+
container.register(SqlApiCoreStorageOperationsFactory);
|
|
8
|
+
container.register(CoreSqlSchemaSetup);
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
export { ApiCoreSqlFeature };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=feature.js.map
|
|
@@ -0,0 +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 request: the implementation of `ApiCoreStorageOperationsFactory`, which\n * `ApiCoreFeature.register` resolves and builds, and the `core` schema setup step. Mirrors\n * `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(CoreSqlSchemaSetup);\n }\n});\n"],"names":["ApiCoreSqlFeature","createFeature","container","SqlApiCoreStorageOperationsFactory","CoreSqlSchemaSetup"],"mappings":";;;AAaO,MAAMA,oBAAoBC,cAAc;IAC3C,MAAM;IACN,UAASC,SAAS;QACdA,UAAU,QAAQ,CAACC;QACnBD,UAAU,QAAQ,CAACE;IACvB;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ApiCoreSqlFeature } from "./feature.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ApiCoreSqlFeature } from "./feature.js";
|
package/createApiCoreSql.d.ts
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import type { Knex } from "knex";
|
|
2
2
|
import type { ApiCoreStorageOperations } from "@webiny/api-core/types/core.js";
|
|
3
|
+
import { TableManager } from "./TableManager.js";
|
|
3
4
|
interface CreateApiCoreSqlParams {
|
|
4
5
|
knex: Knex;
|
|
5
6
|
tableNamePrefix?: string;
|
|
7
|
+
/** The schema was set up before the API took traffic: no table checks at runtime. */
|
|
8
|
+
schemaManaged?: boolean;
|
|
6
9
|
}
|
|
7
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The core storage operations (users, tenancy, security, key-value store) on `tableManager`, which
|
|
12
|
+
* they declare their tables on.
|
|
13
|
+
*/
|
|
14
|
+
export declare const createApiCoreSqlOperations: (knex: Knex, tableManager: TableManager) => ApiCoreStorageOperations;
|
|
15
|
+
/**
|
|
16
|
+
* The core storage operations on a connection. Cheap to build: what the table checks learn is kept
|
|
17
|
+
* for the process (see `TableManager`), so they are built per request.
|
|
18
|
+
*/
|
|
19
|
+
export declare const createApiCoreSql: ({ knex, tableNamePrefix, schemaManaged }: CreateApiCoreSqlParams) => ApiCoreStorageOperations;
|
|
8
20
|
export {};
|
package/createApiCoreSql.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import { ServiceDiscovery } from "@webiny/api-core/features/serviceDiscovery/index.js";
|
|
2
1
|
import { createStorageOperations } from "./adminUsers/index.js";
|
|
3
2
|
import { createStorageOperations as index_js_createStorageOperations } from "./tenancy/index.js";
|
|
4
3
|
import { createStorageOperations as external_security_index_js_createStorageOperations } from "./security/index.js";
|
|
5
4
|
import { createStorageOperations as external_keyValueStore_index_js_createStorageOperations } from "./keyValueStore/index.js";
|
|
6
5
|
import { TableManager } from "./TableManager.js";
|
|
7
|
-
|
|
8
|
-
const createApiCoreSql = ({ knex, tableNamePrefix })=>{
|
|
9
|
-
const tableManager = new TableManager(knex, tableNamePrefix);
|
|
10
|
-
ServiceDiscovery.setLoader(new SqlServiceManifestLoader(knex, tableManager));
|
|
11
|
-
return {
|
|
6
|
+
const createApiCoreSqlOperations = (knex, tableManager)=>({
|
|
12
7
|
usersStorageOperations: createStorageOperations({
|
|
13
8
|
knex,
|
|
14
9
|
tableManager
|
|
@@ -25,8 +20,13 @@ const createApiCoreSql = ({ knex, tableNamePrefix })=>{
|
|
|
25
20
|
knex,
|
|
26
21
|
tableManager
|
|
27
22
|
})
|
|
28
|
-
};
|
|
23
|
+
});
|
|
24
|
+
const createApiCoreSql = ({ knex, tableNamePrefix, schemaManaged })=>{
|
|
25
|
+
const tableManager = new TableManager(knex, tableNamePrefix, {
|
|
26
|
+
schemaManaged
|
|
27
|
+
});
|
|
28
|
+
return createApiCoreSqlOperations(knex, tableManager);
|
|
29
29
|
};
|
|
30
|
-
export { createApiCoreSql };
|
|
30
|
+
export { createApiCoreSql, createApiCoreSqlOperations };
|
|
31
31
|
|
|
32
32
|
//# sourceMappingURL=createApiCoreSql.js.map
|
package/createApiCoreSql.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createApiCoreSql.js","sources":["../src/createApiCoreSql.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type { ApiCoreStorageOperations } from \"@webiny/api-core/types/core.js\";\nimport {
|
|
1
|
+
{"version":3,"file":"createApiCoreSql.js","sources":["../src/createApiCoreSql.ts"],"sourcesContent":["import type { Knex } from \"knex\";\nimport type { ApiCoreStorageOperations } from \"@webiny/api-core/types/core.js\";\nimport { createStorageOperations as createUsersStorageOperations } from \"./adminUsers/index.js\";\nimport { createStorageOperations as createTenancyStorageOperations } from \"./tenancy/index.js\";\nimport { createStorageOperations as createSecurityStorageOperations } from \"./security/index.js\";\nimport { createStorageOperations as createKeyValueStorageOperations } from \"./keyValueStore/index.js\";\nimport { TableManager } from \"./TableManager.js\";\n\ninterface CreateApiCoreSqlParams {\n knex: Knex;\n tableNamePrefix?: string;\n /** The schema was set up before the API took traffic: no table checks at runtime. */\n schemaManaged?: boolean;\n}\n\n/**\n * The core storage operations (users, tenancy, security, key-value store) on `tableManager`, which\n * they declare their tables on.\n */\nexport const createApiCoreSqlOperations = (\n knex: Knex,\n tableManager: TableManager\n): ApiCoreStorageOperations => {\n return {\n usersStorageOperations: createUsersStorageOperations({ knex, tableManager }),\n tenancyStorageOperations: createTenancyStorageOperations({ knex, tableManager }),\n securityStorageOperations: createSecurityStorageOperations({ knex, tableManager }),\n keyValueStorageOperations: createKeyValueStorageOperations({ knex, tableManager })\n };\n};\n\n/**\n * The core storage operations on a connection. Cheap to build: what the table checks learn is kept\n * for the process (see `TableManager`), so they are built per request.\n */\nexport const createApiCoreSql = ({\n knex,\n tableNamePrefix,\n schemaManaged\n}: CreateApiCoreSqlParams): ApiCoreStorageOperations => {\n const tableManager = new TableManager(knex, tableNamePrefix, { schemaManaged });\n return createApiCoreSqlOperations(knex, tableManager);\n};\n"],"names":["createApiCoreSqlOperations","knex","tableManager","createUsersStorageOperations","createTenancyStorageOperations","createSecurityStorageOperations","createKeyValueStorageOperations","createApiCoreSql","tableNamePrefix","schemaManaged","TableManager"],"mappings":";;;;;AAmBO,MAAMA,6BAA6B,CACtCC,MACAC,eAEO;QACH,wBAAwBC,wBAA6B;YAAEF;YAAMC;QAAa;QAC1E,0BAA0BE,iCAA+B;YAAEH;YAAMC;QAAa;QAC9E,2BAA2BG,mDAAgC;YAAEJ;YAAMC;QAAa;QAChF,2BAA2BI,wDAAgC;YAAEL;YAAMC;QAAa;IACpF;AAOG,MAAMK,mBAAmB,CAAC,EAC7BN,IAAI,EACJO,eAAe,EACfC,aAAa,EACQ;IACrB,MAAMP,eAAe,IAAIQ,aAAaT,MAAMO,iBAAiB;QAAEC;IAAc;IAC7E,OAAOT,2BAA2BC,MAAMC;AAC5C"}
|
package/index.d.ts
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
import type { Knex } from "knex";
|
|
2
2
|
export { createApiCoreSql } from "./createApiCoreSql.js";
|
|
3
|
-
export { ApiCoreSqlFeature } from "./
|
|
4
|
-
export
|
|
3
|
+
export { ApiCoreSqlFeature } from "./coreStorage/index.js";
|
|
4
|
+
export { SqlConnectionFeature, setSqlServiceManifestLoader } from "./connection/index.js";
|
|
5
|
+
export type { SqlConnectionConfig } from "./connection/index.js";
|
|
5
6
|
export { getSqlTablePrefix } from "./getSqlTablePrefix.js";
|
|
6
7
|
export { TableManager } from "./TableManager.js";
|
|
7
|
-
export {
|
|
8
|
+
export type { TableManagerOptions } from "./TableManager.js";
|
|
9
|
+
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";
|
|
12
|
+
export { getSchemaMemory } from "./schemaMemory/getSchemaMemory.js";
|
|
13
|
+
export { getConnectionKey } from "./schemaMemory/getConnectionKey.js";
|
|
14
|
+
export { ensureTable, createTableIfMissing, recordTable } from "./schemaMemory/ensureTable.js";
|
|
15
|
+
export type { EnsureTableParams, TableCreator } from "./schemaMemory/ensureTable.js";
|
|
16
|
+
export type { ISchemaMemory } from "./schemaMemory/getSchemaMemory.js";
|
|
17
|
+
export type { SqlStorage } from "./storage/types.js";
|
|
8
18
|
export * from "./connectionRetry/index.js";
|
|
9
|
-
export { SqlServiceManifestLoader } from "./serviceDiscovery/index.js";
|
|
19
|
+
export { SqlServiceManifestLoader, SqlServiceManifestWriter } from "./serviceDiscovery/index.js";
|
|
10
20
|
export { KnexClient } from "./feature/KnexClient/index.js";
|
|
11
21
|
interface IRegisterApiCoreSqlExtension {
|
|
12
22
|
knex: Knex;
|
package/index.js
CHANGED
|
@@ -5,11 +5,16 @@ const registerSQLCore = ({ knex })=>createRegisterExtensionPlugin(async (context
|
|
|
5
5
|
KnexClientFeature.register(context.container, knex);
|
|
6
6
|
});
|
|
7
7
|
export { createApiCoreSql } from "./createApiCoreSql.js";
|
|
8
|
-
export { ApiCoreSqlFeature } from "./
|
|
8
|
+
export { ApiCoreSqlFeature } from "./coreStorage/index.js";
|
|
9
|
+
export { SqlConnectionFeature, setSqlServiceManifestLoader } from "./connection/index.js";
|
|
9
10
|
export { getSqlTablePrefix } from "./getSqlTablePrefix.js";
|
|
10
11
|
export { TableManager } from "./TableManager.js";
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
12
|
+
export { SqlSchemaConfig } from "./schemaConfig/index.js";
|
|
13
|
+
export { SqlSchemaSetup, SqlSchemaSetupRunner, runSchemaSetupSteps } from "./schemaSetup/index.js";
|
|
14
|
+
export { getSchemaMemory } from "./schemaMemory/getSchemaMemory.js";
|
|
15
|
+
export { getConnectionKey } from "./schemaMemory/getConnectionKey.js";
|
|
16
|
+
export { createTableIfMissing, ensureTable, recordTable } from "./schemaMemory/ensureTable.js";
|
|
17
|
+
export { SqlServiceManifestLoader, SqlServiceManifestWriter } from "./serviceDiscovery/index.js";
|
|
13
18
|
export { KnexClient, registerSQLCore };
|
|
14
19
|
|
|
15
20
|
//# 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 \"./
|
|
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 { SqlSchemaSetup, SqlSchemaSetupRunner, runSchemaSetupSteps } from \"./schemaSetup/index.js\";\nexport type {\n ISqlSchemaSetupRequest,\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 } from \"./schemaMemory/ensureTable.js\";\nexport type { ISchemaMemory } from \"./schemaMemory/getSchemaMemory.js\";\nexport type { SqlStorage } from \"./storage/types.js\";\nexport * from \"./connectionRetry/index.js\";\nexport { SqlServiceManifestLoader, SqlServiceManifestWriter } from \"./serviceDiscovery/index.js\";\n\nexport { KnexClient } from \"./feature/KnexClient/index.js\";\n\ninterface IRegisterApiCoreSqlExtension {\n knex: Knex;\n}\n\nexport const registerSQLCore = ({ knex }: IRegisterApiCoreSqlExtension) => {\n return createRegisterExtensionPlugin(async context => {\n KnexClientFeature.register(context.container, knex);\n });\n};\n"],"names":["registerSQLCore","knex","createRegisterExtensionPlugin","context","KnexClientFeature"],"mappings":";;;AAkCO,MAAMA,kBAAkB,CAAC,EAAEC,IAAI,EAAgC,GAC3DC,8BAA8B,OAAMC;QACvCC,kBAAkB,QAAQ,CAACD,QAAQ,SAAS,EAAEF;IAClD"}
|
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.11",
|
|
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.11",
|
|
25
|
+
"@webiny/error": "6.6.0-alpha.11",
|
|
26
|
+
"@webiny/feature": "6.6.0-alpha.11",
|
|
27
|
+
"@webiny/handler": "6.6.0-alpha.11",
|
|
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.11",
|
|
32
32
|
"better-sqlite3": "13.0.3",
|
|
33
33
|
"pg": "8.23.1",
|
|
34
34
|
"typescript": "7.0.2",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface ISqlSchemaConfig {
|
|
2
|
+
/**
|
|
3
|
+
* Whether the schema was set up before the API took traffic (the storage's schema setup ran).
|
|
4
|
+
* When it is, storage code never checks for or creates tables at runtime: no catalog queries
|
|
5
|
+
* and no DDL on a cold start. When it isn't, each table is checked and created on first use.
|
|
6
|
+
*/
|
|
7
|
+
isManaged(): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* The prefix of every table the storage uses. Modules registered after the storage (the
|
|
10
|
+
* Postgres CMS and folder catalog) name their tables with it.
|
|
11
|
+
*/
|
|
12
|
+
readonly tableNamePrefix?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* How the SQL storage finds its tables, set by the storage that registers it. Optional for the
|
|
16
|
+
* code that only reads `isManaged()`: when it isn't registered, tables are checked and created on
|
|
17
|
+
* first use.
|
|
18
|
+
*/
|
|
19
|
+
export declare const SqlSchemaConfig: import("@webiny/di").Abstraction<ISqlSchemaConfig>;
|
|
20
|
+
export declare namespace SqlSchemaConfig {
|
|
21
|
+
type Interface = ISqlSchemaConfig;
|
|
22
|
+
}
|