@webiny/api-event-handler-standalone-sql 6.6.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Webiny
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # @webiny/api-event-handler-standalone-sql
2
+
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
6
+
7
+ πŸ“˜ **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
8
+
9
+ ---
10
+
11
+ _This README file is automatically generated during the publish process._
@@ -0,0 +1,19 @@
1
+ import { type Knex } from "knex";
2
+ export interface CreatePostgresConnectionOptions {
3
+ host?: string;
4
+ port?: number;
5
+ user?: string;
6
+ password?: string;
7
+ database?: string;
8
+ /**
9
+ * Optional additional Knex connection config (SSL, pool size, etc.).
10
+ * Overrides values from env vars when both are set.
11
+ */
12
+ connection?: Partial<Knex.PgConnectionConfig>;
13
+ }
14
+ /**
15
+ * Build a Knex client backed by a Postgres database. Connection parameters are read from
16
+ * environment variables set by `<Infra.Postgres>` in webiny.config, with explicit options
17
+ * taking precedence.
18
+ */
19
+ export declare function createPostgresConnection(options?: CreatePostgresConnectionOptions): Knex;
@@ -0,0 +1,77 @@
1
+ import node_fs from "node:fs";
2
+ import knex from "knex";
3
+ import { toBoolean } from "@webiny/stdlib";
4
+ const envBool = (name)=>{
5
+ const value = process.env[name];
6
+ return void 0 === value ? void 0 : toBoolean(value);
7
+ };
8
+ const envInt = (name)=>{
9
+ const v = process.env[name];
10
+ if (void 0 === v) return;
11
+ const n = Number(v);
12
+ return isNaN(n) ? void 0 : n;
13
+ };
14
+ function createPostgresConnection(options = {}) {
15
+ const host = options.host || process.env.WEBINY_PG_HOST;
16
+ const port = options.port || envInt("WEBINY_PG_PORT");
17
+ const user = options.user || process.env.WEBINY_PG_USER;
18
+ const password = options.password || process.env.WEBINY_PG_PASSWORD;
19
+ const database = options.database || process.env.WEBINY_PG_DATABASE;
20
+ if (!host) throw new Error('Postgres host is not set. Configure via <Infra.Postgres host="..." /> in webiny.config.');
21
+ if (!port) throw new Error("Postgres port is not set. Configure via <Infra.Postgres port={...} /> in webiny.config.");
22
+ if (!user) throw new Error('Postgres user is not set. Configure via <Infra.Postgres user="..." /> in webiny.config.');
23
+ if (!password) throw new Error('Postgres password is not set. Configure via <Infra.Postgres password="..." /> in webiny.config.');
24
+ if (!database) throw new Error('Postgres database is not set. Configure via <Infra.Postgres database="..." /> in webiny.config.');
25
+ const connectionConfig = {
26
+ host,
27
+ port,
28
+ user,
29
+ password,
30
+ database
31
+ };
32
+ const connectionString = process.env.WEBINY_PG_CONNECTION_STRING;
33
+ if (connectionString) connectionConfig.connectionString = connectionString;
34
+ const sslCa = process.env.WEBINY_PG_SSL_CA;
35
+ const sslKey = process.env.WEBINY_PG_SSL_KEY;
36
+ const sslCert = process.env.WEBINY_PG_SSL_CERT;
37
+ const sslRejectUnauthorized = envBool("WEBINY_PG_SSL_REJECT_UNAUTHORIZED");
38
+ if (sslCa || sslKey || sslCert || void 0 !== sslRejectUnauthorized) {
39
+ const sslConfig = {};
40
+ if (sslCa) sslConfig.ca = node_fs.readFileSync(sslCa, "utf8");
41
+ if (sslKey) sslConfig.key = node_fs.readFileSync(sslKey, "utf8");
42
+ if (sslCert) sslConfig.cert = node_fs.readFileSync(sslCert, "utf8");
43
+ if (void 0 !== sslRejectUnauthorized) sslConfig.rejectUnauthorized = sslRejectUnauthorized;
44
+ connectionConfig.ssl = sslConfig;
45
+ } else {
46
+ const ssl = envBool("WEBINY_PG_SSL");
47
+ if (void 0 !== ssl) connectionConfig.ssl = ssl;
48
+ }
49
+ const applicationName = process.env.WEBINY_PG_APPLICATION_NAME;
50
+ if (applicationName) connectionConfig.application_name = applicationName;
51
+ const connectionTimeoutMillis = envInt("WEBINY_PG_CONNECTION_TIMEOUT_MILLIS");
52
+ if (void 0 !== connectionTimeoutMillis) connectionConfig.connectionTimeoutMillis = connectionTimeoutMillis;
53
+ const statementTimeout = envInt("WEBINY_PG_STATEMENT_TIMEOUT");
54
+ if (void 0 !== statementTimeout) connectionConfig.statement_timeout = statementTimeout;
55
+ const queryTimeout = envInt("WEBINY_PG_QUERY_TIMEOUT");
56
+ if (void 0 !== queryTimeout) connectionConfig.query_timeout = queryTimeout;
57
+ const idleInTransactionSessionTimeout = envInt("WEBINY_PG_IDLE_IN_TRANSACTION_SESSION_TIMEOUT");
58
+ if (void 0 !== idleInTransactionSessionTimeout) connectionConfig.idle_in_transaction_session_timeout = idleInTransactionSessionTimeout;
59
+ const parseInputDatesAsUTC = envBool("WEBINY_PG_PARSE_INPUT_DATES_AS_UTC");
60
+ if (void 0 !== parseInputDatesAsUTC) connectionConfig.parseInputDatesAsUTC = parseInputDatesAsUTC;
61
+ const pgOptions = process.env.WEBINY_PG_OPTIONS;
62
+ if (pgOptions) connectionConfig.options = pgOptions;
63
+ const keepAlive = envBool("WEBINY_PG_KEEP_ALIVE");
64
+ if (void 0 !== keepAlive) connectionConfig.keepAlive = keepAlive;
65
+ const keepAliveInitialDelayMillis = envInt("WEBINY_PG_KEEP_ALIVE_INITIAL_DELAY_MILLIS");
66
+ if (void 0 !== keepAliveInitialDelayMillis) connectionConfig.keepAliveInitialDelayMillis = keepAliveInitialDelayMillis;
67
+ return knex({
68
+ client: "pg",
69
+ connection: {
70
+ ...connectionConfig,
71
+ ...options.connection
72
+ }
73
+ });
74
+ }
75
+ export { createPostgresConnection };
76
+
77
+ //# sourceMappingURL=createPostgresConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createPostgresConnection.js","sources":["../src/createPostgresConnection.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport knex, { type Knex } from \"knex\";\nimport type { ConnectionOptions } from \"node:tls\";\nimport { toBoolean } from \"@webiny/stdlib\";\n\nexport interface CreatePostgresConnectionOptions {\n host?: string;\n port?: number;\n user?: string;\n password?: string;\n database?: string;\n /**\n * Optional additional Knex connection config (SSL, pool size, etc.).\n * Overrides values from env vars when both are set.\n */\n connection?: Partial<Knex.PgConnectionConfig>;\n}\n\nconst envBool = (name: string): boolean | undefined => {\n const value = process.env[name];\n // Only convert when the var is actually set β€” an unset var must stay `undefined`, not become\n // `false`. Callers rely on the `undefined` distinction (e.g. the SSL config is only applied when a\n // WEBINY_PG_SSL* var is explicitly present); returning `false` for unset would always trigger it.\n return value === undefined ? undefined : toBoolean(value);\n};\n\nconst envInt = (name: string): number | undefined => {\n const v = process.env[name];\n if (v === undefined) {\n return undefined;\n }\n const n = Number(v);\n return isNaN(n) ? undefined : n;\n};\n\n/**\n * Build a Knex client backed by a Postgres database. Connection parameters are read from\n * environment variables set by `<Infra.Postgres>` in webiny.config, with explicit options\n * taking precedence.\n */\nexport function createPostgresConnection(options: CreatePostgresConnectionOptions = {}): Knex {\n const host = options.host || process.env.WEBINY_PG_HOST;\n const port = options.port || envInt(\"WEBINY_PG_PORT\");\n const user = options.user || process.env.WEBINY_PG_USER;\n const password = options.password || process.env.WEBINY_PG_PASSWORD;\n const database = options.database || process.env.WEBINY_PG_DATABASE;\n\n if (!host) {\n throw new Error(\n 'Postgres host is not set. Configure via <Infra.Postgres host=\"...\" /> in webiny.config.'\n );\n }\n if (!port) {\n throw new Error(\n \"Postgres port is not set. Configure via <Infra.Postgres port={...} /> in webiny.config.\"\n );\n }\n if (!user) {\n throw new Error(\n 'Postgres user is not set. Configure via <Infra.Postgres user=\"...\" /> in webiny.config.'\n );\n }\n if (!password) {\n throw new Error(\n 'Postgres password is not set. Configure via <Infra.Postgres password=\"...\" /> in webiny.config.'\n );\n }\n if (!database) {\n throw new Error(\n 'Postgres database is not set. Configure via <Infra.Postgres database=\"...\" /> in webiny.config.'\n );\n }\n\n const connectionConfig: Knex.PgConnectionConfig = {\n host,\n port,\n user,\n password,\n database\n };\n\n const connectionString = process.env.WEBINY_PG_CONNECTION_STRING;\n if (connectionString) {\n connectionConfig.connectionString = connectionString;\n }\n\n const sslCa = process.env.WEBINY_PG_SSL_CA;\n const sslKey = process.env.WEBINY_PG_SSL_KEY;\n const sslCert = process.env.WEBINY_PG_SSL_CERT;\n const sslRejectUnauthorized = envBool(\"WEBINY_PG_SSL_REJECT_UNAUTHORIZED\");\n\n if (sslCa || sslKey || sslCert || sslRejectUnauthorized !== undefined) {\n const sslConfig: ConnectionOptions = {};\n if (sslCa) {\n sslConfig.ca = fs.readFileSync(sslCa, \"utf8\");\n }\n if (sslKey) {\n sslConfig.key = fs.readFileSync(sslKey, \"utf8\");\n }\n if (sslCert) {\n sslConfig.cert = fs.readFileSync(sslCert, \"utf8\");\n }\n if (sslRejectUnauthorized !== undefined) {\n sslConfig.rejectUnauthorized = sslRejectUnauthorized;\n }\n connectionConfig.ssl = sslConfig;\n } else {\n const ssl = envBool(\"WEBINY_PG_SSL\");\n if (ssl !== undefined) {\n connectionConfig.ssl = ssl;\n }\n }\n\n const applicationName = process.env.WEBINY_PG_APPLICATION_NAME;\n if (applicationName) {\n connectionConfig.application_name = applicationName;\n }\n\n const connectionTimeoutMillis = envInt(\"WEBINY_PG_CONNECTION_TIMEOUT_MILLIS\");\n if (connectionTimeoutMillis !== undefined) {\n connectionConfig.connectionTimeoutMillis = connectionTimeoutMillis;\n }\n\n const statementTimeout = envInt(\"WEBINY_PG_STATEMENT_TIMEOUT\");\n if (statementTimeout !== undefined) {\n connectionConfig.statement_timeout = statementTimeout;\n }\n\n const queryTimeout = envInt(\"WEBINY_PG_QUERY_TIMEOUT\");\n if (queryTimeout !== undefined) {\n connectionConfig.query_timeout = queryTimeout;\n }\n\n const idleInTransactionSessionTimeout = envInt(\"WEBINY_PG_IDLE_IN_TRANSACTION_SESSION_TIMEOUT\");\n if (idleInTransactionSessionTimeout !== undefined) {\n connectionConfig.idle_in_transaction_session_timeout = idleInTransactionSessionTimeout;\n }\n\n const parseInputDatesAsUTC = envBool(\"WEBINY_PG_PARSE_INPUT_DATES_AS_UTC\");\n if (parseInputDatesAsUTC !== undefined) {\n connectionConfig.parseInputDatesAsUTC = parseInputDatesAsUTC;\n }\n\n const pgOptions = process.env.WEBINY_PG_OPTIONS;\n if (pgOptions) {\n connectionConfig.options = pgOptions;\n }\n\n const keepAlive = envBool(\"WEBINY_PG_KEEP_ALIVE\");\n if (keepAlive !== undefined) {\n connectionConfig.keepAlive = keepAlive;\n }\n\n const keepAliveInitialDelayMillis = envInt(\"WEBINY_PG_KEEP_ALIVE_INITIAL_DELAY_MILLIS\");\n if (keepAliveInitialDelayMillis !== undefined) {\n connectionConfig.keepAliveInitialDelayMillis = keepAliveInitialDelayMillis;\n }\n\n return knex({\n client: \"pg\",\n connection: {\n ...connectionConfig,\n ...options.connection\n }\n });\n}\n"],"names":["envBool","name","value","process","undefined","toBoolean","envInt","v","n","Number","isNaN","createPostgresConnection","options","host","port","user","password","database","Error","connectionConfig","connectionString","sslCa","sslKey","sslCert","sslRejectUnauthorized","sslConfig","fs","ssl","applicationName","connectionTimeoutMillis","statementTimeout","queryTimeout","idleInTransactionSessionTimeout","parseInputDatesAsUTC","pgOptions","keepAlive","keepAliveInitialDelayMillis","knex"],"mappings":"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"}
@@ -0,0 +1,19 @@
1
+ import { type Knex } from "knex";
2
+ export interface CreateSqliteConnectionOptions {
3
+ /**
4
+ * Path to the SQLite database file. Defaults to `WEBINY_SQL_FILENAME` (baked by
5
+ * `<Infra.Sqlite filename="..." />` in webiny.config).
6
+ */
7
+ filename?: string;
8
+ }
9
+ /**
10
+ * Build a Knex client backed by a local SQLite file (better-sqlite3) for the standalone server
11
+ * hosting type. This is the default standalone storage connection; a real deployment can instead pass its
12
+ * own Knex client (Postgres/MySQL) straight to `createSqlApiHandler`.
13
+ *
14
+ * The database file is mandatory: it comes from `WEBINY_SQL_FILENAME` (or an explicit `filename`),
15
+ * which `<Infra.Sqlite>` resolves to an absolute, project-root path so data survives rebuilds. There
16
+ * is no implicit default β€” a cwd-relative fallback would land in the disposable app workspace and
17
+ * lose data on the next build.
18
+ */
19
+ export declare function createSqliteConnection(options?: CreateSqliteConnectionOptions): Knex;
@@ -0,0 +1,20 @@
1
+ import node_fs from "node:fs";
2
+ import node_path from "node:path";
3
+ import knex from "knex";
4
+ function createSqliteConnection(options = {}) {
5
+ const filename = options.filename || process.env.WEBINY_SQL_FILENAME;
6
+ if (!filename) throw new Error('WEBINY_SQL_FILENAME is not set. Configure the database via <Infra.Sqlite filename="..." /> in webiny.config.');
7
+ node_fs.mkdirSync(node_path.dirname(filename), {
8
+ recursive: true
9
+ });
10
+ return knex({
11
+ client: "better-sqlite3",
12
+ connection: {
13
+ filename
14
+ },
15
+ useNullAsDefault: true
16
+ });
17
+ }
18
+ export { createSqliteConnection };
19
+
20
+ //# sourceMappingURL=createSqliteConnection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createSqliteConnection.js","sources":["../src/createSqliteConnection.ts"],"sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport knex, { type Knex } from \"knex\";\n\nexport interface CreateSqliteConnectionOptions {\n /**\n * Path to the SQLite database file. Defaults to `WEBINY_SQL_FILENAME` (baked by\n * `<Infra.Sqlite filename=\"...\" />` in webiny.config).\n */\n filename?: string;\n}\n\n/**\n * Build a Knex client backed by a local SQLite file (better-sqlite3) for the standalone server\n * hosting type. This is the default standalone storage connection; a real deployment can instead pass its\n * own Knex client (Postgres/MySQL) straight to `createSqlApiHandler`.\n *\n * The database file is mandatory: it comes from `WEBINY_SQL_FILENAME` (or an explicit `filename`),\n * which `<Infra.Sqlite>` resolves to an absolute, project-root path so data survives rebuilds. There\n * is no implicit default β€” a cwd-relative fallback would land in the disposable app workspace and\n * lose data on the next build.\n */\nexport function createSqliteConnection(options: CreateSqliteConnectionOptions = {}): Knex {\n const filename = options.filename || process.env.WEBINY_SQL_FILENAME;\n if (!filename) {\n throw new Error(\n `WEBINY_SQL_FILENAME is not set. Configure the database via <Infra.Sqlite filename=\"...\" /> in webiny.config.`\n );\n }\n\n // better-sqlite3 won't create missing parent dirs β€” ensure the target directory exists.\n fs.mkdirSync(path.dirname(filename), { recursive: true });\n\n return knex({\n client: \"better-sqlite3\",\n connection: { filename },\n useNullAsDefault: true\n });\n}\n"],"names":["createSqliteConnection","options","filename","process","Error","fs","path","knex"],"mappings":";;;AAsBO,SAASA,uBAAuBC,UAAyC,CAAC,CAAC;IAC9E,MAAMC,WAAWD,QAAQ,QAAQ,IAAIE,QAAQ,GAAG,CAAC,mBAAmB;IACpE,IAAI,CAACD,UACD,MAAM,IAAIE,MACN;IAKRC,QAAAA,SAAY,CAACC,UAAAA,OAAY,CAACJ,WAAW;QAAE,WAAW;IAAK;IAEvD,OAAOK,KAAK;QACR,QAAQ;QACR,YAAY;YAAEL;QAAS;QACvB,kBAAkB;IACtB;AACJ"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Webiny API handler for the standalone Node server transport with SQL storage.
3
+ *
4
+ * Thin variant over the transport base (@webiny/api-event-handler-standalone): supplies the SQL storage
5
+ * wiring AND the self-hosted identity provider (JWT IdP + SQL credential storage). CMS, core, and
6
+ * websockets storage are DI Features registered directly on the container. ACO and audit-logs
7
+ * remain legacy RegisterExtensionPlugins applied via `registerExtensions`.
8
+ *
9
+ * The caller supplies the Knex client (there is no single canonical connection for a standalone DB).
10
+ * The JWT signing secret is configured via `<SelfHostedAuth signingSecret>` (BuildParams).
11
+ */
12
+ import type { Knex } from "knex";
13
+ import { type CreateWebinyApiHandlerConfig as BaseConfig } from "@webiny/api-event-handler-standalone";
14
+ export type CreateSqlApiHandlerConfig = Pick<BaseConfig, "extensions"> & {
15
+ /**
16
+ * Knex client for the SQL database. Required β€” the caller owns the connection (there is no single
17
+ * canonical standalone DB connection to default to).
18
+ */
19
+ knex: Knex;
20
+ /**
21
+ * Optional table-name prefix, threaded to every SQL storage operation.
22
+ */
23
+ tableNamePrefix?: string;
24
+ };
25
+ export declare function createSqlApiHandler(config: CreateSqlApiHandlerConfig): Promise<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>>;
@@ -0,0 +1,49 @@
1
+ import { registerExtensions } from "@webiny/handler";
2
+ import { createWebinyApiHandler } from "@webiny/api-event-handler-standalone";
3
+ import { ApiCoreSqlFeature, registerSQLCore } from "@webiny/api-core-sql";
4
+ import { HeadlessCmsSqlFeature } from "@webiny/api-headless-cms-sql";
5
+ import { registerAcoSqlStorageOperations } from "@webiny/api-aco-sql";
6
+ import { registerAuditLogsSqlStorageOperations } from "@webiny/api-audit-logs-sql";
7
+ import { WebsocketsSqlFeature } from "@webiny/api-websockets-sql";
8
+ import { SelfHostedAuthApiFeature } from "@webiny/self-hosted-auth";
9
+ import { SelfHostedAuthSqlFeature } from "@webiny/self-hosted-auth-sql";
10
+ function createSqlApiHandler(config) {
11
+ const { knex, tableNamePrefix } = config;
12
+ return createWebinyApiHandler({
13
+ extensions: config.extensions,
14
+ registerRootStorage: async (container)=>{
15
+ ApiCoreSqlFeature.register(container, {
16
+ knex,
17
+ tableNamePrefix
18
+ });
19
+ WebsocketsSqlFeature.register(container, {
20
+ tableNamePrefix
21
+ });
22
+ SelfHostedAuthSqlFeature.register(container, {
23
+ knex,
24
+ tableNamePrefix
25
+ });
26
+ SelfHostedAuthApiFeature.register(container);
27
+ HeadlessCmsSqlFeature.register(container, {
28
+ knex,
29
+ tableNamePrefix
30
+ });
31
+ await registerExtensions(container, [
32
+ registerSQLCore({
33
+ knex
34
+ }),
35
+ registerAcoSqlStorageOperations({
36
+ knex,
37
+ tableNamePrefix
38
+ }),
39
+ registerAuditLogsSqlStorageOperations({
40
+ knex,
41
+ tableNamePrefix
42
+ })
43
+ ]);
44
+ }
45
+ });
46
+ }
47
+ export { createSqlApiHandler };
48
+
49
+ //# sourceMappingURL=createWebinyApiHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createWebinyApiHandler.js","sources":["../src/createWebinyApiHandler.ts"],"sourcesContent":["/**\n * Webiny API handler for the standalone Node server transport with SQL storage.\n *\n * Thin variant over the transport base (@webiny/api-event-handler-standalone): supplies the SQL storage\n * wiring AND the self-hosted identity provider (JWT IdP + SQL credential storage). CMS, core, and\n * websockets storage are DI Features registered directly on the container. ACO and audit-logs\n * remain legacy RegisterExtensionPlugins applied via `registerExtensions`.\n *\n * The caller supplies the Knex client (there is no single canonical connection for a standalone DB).\n * The JWT signing secret is configured via `<SelfHostedAuth signingSecret>` (BuildParams).\n */\nimport type { Knex } from \"knex\";\nimport { registerExtensions } from \"@webiny/handler\";\nimport {\n createWebinyApiHandler as createBaseHandler,\n type CreateWebinyApiHandlerConfig as BaseConfig\n} from \"@webiny/api-event-handler-standalone\";\nimport { ApiCoreSqlFeature, registerSQLCore } from \"@webiny/api-core-sql\";\nimport { HeadlessCmsSqlFeature } from \"@webiny/api-headless-cms-sql\";\nimport { registerAcoSqlStorageOperations } from \"@webiny/api-aco-sql\";\nimport { registerAuditLogsSqlStorageOperations } from \"@webiny/api-audit-logs-sql\";\nimport { WebsocketsSqlFeature } from \"@webiny/api-websockets-sql\";\nimport { SelfHostedAuthApiFeature } from \"@webiny/self-hosted-auth\";\nimport { SelfHostedAuthSqlFeature } from \"@webiny/self-hosted-auth-sql\";\n\nexport type CreateSqlApiHandlerConfig = Pick<BaseConfig, \"extensions\"> & {\n /**\n * Knex client for the SQL database. Required β€” the caller owns the connection (there is no single\n * canonical standalone DB connection to default to).\n */\n knex: Knex;\n /**\n * Optional table-name prefix, threaded to every SQL storage operation.\n */\n tableNamePrefix?: string;\n};\n\nexport function createSqlApiHandler(config: CreateSqlApiHandlerConfig) {\n const { knex, tableNamePrefix } = config;\n\n return createBaseHandler({\n extensions: config.extensions,\n registerRootStorage: async container => {\n // Clean DI Features: SQL core storage-ops factory + websockets storage.\n ApiCoreSqlFeature.register(container, { knex, tableNamePrefix });\n WebsocketsSqlFeature.register(container, { tableNamePrefix });\n\n // Identity provider: the self-hosted JWT IdP + its SQL credential storage. Registered in\n // the root so the RequestIdentityLoader (driven by NodeHttpIdentityLoaderDecorator) can\n // resolve it. SelfHostedAuthSqlFeature supplies CredentialsStorageOperations over Knex.\n SelfHostedAuthSqlFeature.register(container, { knex, tableNamePrefix });\n // The JWT signing secret comes from <SelfHostedAuth signingSecret> (BuildParams).\n SelfHostedAuthApiFeature.register(container);\n\n HeadlessCmsSqlFeature.register(container, { knex, tableNamePrefix });\n\n await registerExtensions(container, [\n registerSQLCore({ knex }),\n registerAcoSqlStorageOperations({ knex, tableNamePrefix }),\n registerAuditLogsSqlStorageOperations({ knex, tableNamePrefix })\n ]);\n }\n });\n}\n"],"names":["createSqlApiHandler","config","knex","tableNamePrefix","createBaseHandler","container","ApiCoreSqlFeature","WebsocketsSqlFeature","SelfHostedAuthSqlFeature","SelfHostedAuthApiFeature","HeadlessCmsSqlFeature","registerExtensions","registerSQLCore","registerAcoSqlStorageOperations","registerAuditLogsSqlStorageOperations"],"mappings":";;;;;;;;;AAqCO,SAASA,oBAAoBC,MAAiC;IACjE,MAAM,EAAEC,IAAI,EAAEC,eAAe,EAAE,GAAGF;IAElC,OAAOG,uBAAkB;QACrB,YAAYH,OAAO,UAAU;QAC7B,qBAAqB,OAAMI;YAEvBC,kBAAkB,QAAQ,CAACD,WAAW;gBAAEH;gBAAMC;YAAgB;YAC9DI,qBAAqB,QAAQ,CAACF,WAAW;gBAAEF;YAAgB;YAK3DK,yBAAyB,QAAQ,CAACH,WAAW;gBAAEH;gBAAMC;YAAgB;YAErEM,yBAAyB,QAAQ,CAACJ;YAElCK,sBAAsB,QAAQ,CAACL,WAAW;gBAAEH;gBAAMC;YAAgB;YAElE,MAAMQ,mBAAmBN,WAAW;gBAChCO,gBAAgB;oBAAEV;gBAAK;gBACvBW,gCAAgC;oBAAEX;oBAAMC;gBAAgB;gBACxDW,sCAAsC;oBAAEZ;oBAAMC;gBAAgB;aACjE;QACL;IACJ;AACJ"}
package/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export { createSqlApiHandler } from "./createWebinyApiHandler.js";
2
+ export type { CreateSqlApiHandlerConfig } from "./createWebinyApiHandler.js";
3
+ export { createSqliteConnection } from "./createSqliteConnection.js";
4
+ export type { CreateSqliteConnectionOptions } from "./createSqliteConnection.js";
5
+ export { createPostgresConnection } from "./createPostgresConnection.js";
6
+ export type { CreatePostgresConnectionOptions } from "./createPostgresConnection.js";
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { createSqlApiHandler } from "./createWebinyApiHandler.js";
2
+ export { createSqliteConnection } from "./createSqliteConnection.js";
3
+ export { createPostgresConnection } from "./createPostgresConnection.js";
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@webiny/api-event-handler-standalone-sql",
3
+ "version": "6.6.0-alpha.4",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "exports": {
7
+ ".": "./index.js",
8
+ "./*": "./*"
9
+ },
10
+ "types": "index.d.ts",
11
+ "description": "EXPERIMENTAL: Webiny API handler for the Node server transport with SQL storage.",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/webiny/webiny-js.git"
15
+ },
16
+ "contributors": [
17
+ "Webiny Team"
18
+ ],
19
+ "license": "MIT",
20
+ "dependencies": {
21
+ "@webiny/api-aco-sql": "6.6.0-alpha.4",
22
+ "@webiny/api-audit-logs-sql": "6.6.0-alpha.4",
23
+ "@webiny/api-core-sql": "6.6.0-alpha.4",
24
+ "@webiny/api-event-handler-standalone": "6.6.0-alpha.4",
25
+ "@webiny/api-headless-cms-sql": "6.6.0-alpha.4",
26
+ "@webiny/api-websockets-sql": "6.6.0-alpha.4",
27
+ "@webiny/handler": "6.6.0-alpha.4",
28
+ "@webiny/self-hosted-auth": "6.6.0-alpha.4",
29
+ "@webiny/self-hosted-auth-sql": "6.6.0-alpha.4",
30
+ "@webiny/stdlib": "0.0.17",
31
+ "better-sqlite3": "13.0.3",
32
+ "knex": "3.3.0",
33
+ "pg": "8.23.0"
34
+ },
35
+ "devDependencies": {
36
+ "@webiny/build-tools": "6.6.0-alpha.4",
37
+ "rimraf": "6.1.3",
38
+ "typescript": "7.0.2",
39
+ "vitest": "4.1.11"
40
+ },
41
+ "adio": {
42
+ "ignore": {
43
+ "dependencies": [
44
+ "better-sqlite3",
45
+ "pg"
46
+ ]
47
+ }
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "webiny": {
53
+ "publishFrom": "dist"
54
+ }
55
+ }