@wild-framework/database-mysql 0.0.0-stage → 0.2.0

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) 2026 Wild Framework contributors
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/dist/ddl.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Generate `CREATE TABLE IF NOT EXISTS` statements from a Drizzle schema
3
+ * object for MySQL.
4
+ *
5
+ * Auto-incrementing ids use `AUTO_INCREMENT` (from Drizzle's
6
+ * `.autoincrement()`); identifiers are backtick-quoted.
7
+ */
8
+ export declare function generateMysqlDdl(schema: Record<string, unknown>): string[];
9
+ //# sourceMappingURL=ddl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ddl.d.ts","sourceRoot":"","sources":["../src/ddl.ts"],"names":[],"mappings":"AAmBA;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,EAAE,CAwB1E"}
package/dist/ddl.js ADDED
@@ -0,0 +1,61 @@
1
+ import { getTableConfig } from "drizzle-orm/mysql-core";
2
+ /**
3
+ * Generate `CREATE TABLE IF NOT EXISTS` statements from a Drizzle schema
4
+ * object for MySQL.
5
+ *
6
+ * Auto-incrementing ids use `AUTO_INCREMENT` (from Drizzle's
7
+ * `.autoincrement()`); identifiers are backtick-quoted.
8
+ */
9
+ export function generateMysqlDdl(schema) {
10
+ const statements = [];
11
+ for (const table of Object.values(schema)) {
12
+ if (!table || typeof table !== "object")
13
+ continue;
14
+ let config;
15
+ try {
16
+ config = getTableConfig(table);
17
+ }
18
+ catch {
19
+ continue; // not a table (view, relation, …)
20
+ }
21
+ const columns = config.columns;
22
+ if (columns.length === 0)
23
+ continue;
24
+ const lines = columns.map((column) => ` ${columnSql(column)}`);
25
+ statements.push(`CREATE TABLE IF NOT EXISTS \`${config.name}\` (\n${lines.join(",\n")}\n);`);
26
+ }
27
+ return statements;
28
+ }
29
+ /** Render a single column definition for MySQL. */
30
+ function columnSql(column) {
31
+ const parts = [`\`${column.name}\``, column.getSQLType?.() ?? "text"];
32
+ if (column.autoIncrement)
33
+ parts.push("AUTO_INCREMENT");
34
+ if (column.primary)
35
+ parts.push("PRIMARY KEY");
36
+ if (column.notNull)
37
+ parts.push("NOT NULL");
38
+ if (column.isUnique)
39
+ parts.push("UNIQUE");
40
+ const def = literalDefault(column);
41
+ if (def !== undefined)
42
+ parts.push(`DEFAULT ${def}`);
43
+ return parts.join(" ");
44
+ }
45
+ /** Render a literal default; function/SQL-expression defaults are left out. */
46
+ function literalDefault(column) {
47
+ if (!column.hasDefault)
48
+ return undefined;
49
+ const value = column.default;
50
+ if (value === null)
51
+ return "NULL";
52
+ if (typeof value === "number")
53
+ return String(value);
54
+ if (typeof value === "boolean")
55
+ return value ? "1" : "0";
56
+ if (typeof value === "string")
57
+ return `'${value.replace(/'/g, "''")}'`;
58
+ // Non-literal (SQL expression, function, …) — leave to migrations.
59
+ return undefined;
60
+ }
61
+ //# sourceMappingURL=ddl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ddl.js","sourceRoot":"","sources":["../src/ddl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAmBxD;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAA+B;IAC5D,MAAM,UAAU,GAAa,EAAE,CAAC;IAEhC,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QACxC,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,SAAS;QAElD,IAAI,MAA+C,CAAC;QACpD,IAAI,CAAC;YACD,MAAM,GAAG,cAAc,CAAC,KAA6C,CAGpE,CAAC;QACN,CAAC;QAAC,MAAM,CAAC;YACL,SAAS,CAAC,kCAAkC;QAChD,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC/B,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QAEnC,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,KAAK,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAChE,UAAU,CAAC,IAAI,CAAC,gCAAgC,MAAM,CAAC,IAAI,SAAS,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IACjG,CAAC;IAED,OAAO,UAAU,CAAC;AACtB,CAAC;AAED,mDAAmD;AACnD,SAAS,SAAS,CAAC,MAAkB;IACjC,MAAM,KAAK,GAAa,CAAC,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,MAAM,CAAC,UAAU,EAAE,EAAE,IAAI,MAA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mysql2/promise";
4
+ /**
5
+ * Configuration for the MySQL driver.
6
+ */
7
+ export interface MysqlConfig<TSchema extends Record<string, unknown>> {
8
+ /** MySQL connection URI (e.g. `mysql://user:pass@host:3306/db`). */
9
+ uri?: string;
10
+ /** A pre-built pool — for advanced use or tests. */
11
+ pool?: mysql.Pool;
12
+ /** Optional Drizzle schema object (tables). */
13
+ schema?: TSchema;
14
+ /**
15
+ * Create tables from the schema at connect time (dev-friendly).
16
+ * Set false to rely on migrations.
17
+ * Defaults to true.
18
+ */
19
+ autoCreate?: boolean;
20
+ }
21
+ /**
22
+ * MySQL driver implementing `DatabaseDriver` and `SqlExecutor`.
23
+ *
24
+ * Backed by `mysql2` + Drizzle (`drizzle-orm/mysql2`). The `db` getter
25
+ * returns the typed Drizzle instance for ORM queries; `exec`/`all` expose
26
+ * raw SQL for migrations.
27
+ */
28
+ export declare class MysqlDriver<TSchema extends Record<string, unknown>> implements DatabaseDriver, SqlExecutor {
29
+ private config;
30
+ private pool;
31
+ private drizzleDb;
32
+ private connected;
33
+ constructor(config: MysqlConfig<TSchema>);
34
+ connect(): Promise<void>;
35
+ close(): Promise<void>;
36
+ isConnected(): boolean;
37
+ /** Run one or more `;`-separated SQL statements. */
38
+ exec(sql: string): Promise<void>;
39
+ /** Run a query and return its rows. */
40
+ all<T = Row>(sql: string): Promise<T[]>;
41
+ private requirePool;
42
+ /**
43
+ * The typed Drizzle instance for queries.
44
+ *
45
+ * Throws if the driver is not connected.
46
+ */
47
+ get db(): MySql2Database<TSchema>;
48
+ }
49
+ //# sourceMappingURL=driver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"driver.d.ts","sourceRoot":"","sources":["../src/driver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAC;AAEjF,OAAO,EAAW,KAAK,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,KAAK,MAAM,gBAAgB,CAAC;AAGnC;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAChE,oEAAoE;IACpE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,IAAI,CAAC,EAAE,KAAK,CAAC,IAAI,CAAC;IAClB,+CAA+C;IAC/C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;GAMG;AACH,qBAAa,WAAW,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAC5D,YAAW,cAAc,EAAE,WAAW;IAM1B,OAAO,CAAC,MAAM;IAJ1B,OAAO,CAAC,IAAI,CAA2B;IACvC,OAAO,CAAC,SAAS,CAAwC;IACzD,OAAO,CAAC,SAAS,CAAS;gBAEN,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC;IAE1C,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAiBxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAU5B,WAAW,IAAI,OAAO;IAQtB,oDAAoD;IAC9C,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOtC,uCAAuC;IACjC,GAAG,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAK7C,OAAO,CAAC,WAAW;IAOnB;;;;OAIG;IACH,IAAI,EAAE,IAAI,cAAc,CAAC,OAAO,CAAC,CAKhC;CACJ"}
package/dist/driver.js ADDED
@@ -0,0 +1,78 @@
1
+ import { splitSqlStatements } from "@wild-framework/database";
2
+ import { drizzle } from "drizzle-orm/mysql2";
3
+ import mysql from "mysql2/promise";
4
+ import { generateMysqlDdl } from "./ddl.js";
5
+ /**
6
+ * MySQL driver implementing `DatabaseDriver` and `SqlExecutor`.
7
+ *
8
+ * Backed by `mysql2` + Drizzle (`drizzle-orm/mysql2`). The `db` getter
9
+ * returns the typed Drizzle instance for ORM queries; `exec`/`all` expose
10
+ * raw SQL for migrations.
11
+ */
12
+ export class MysqlDriver {
13
+ config;
14
+ pool = null;
15
+ drizzleDb = null;
16
+ connected = false;
17
+ constructor(config) {
18
+ this.config = config;
19
+ }
20
+ async connect() {
21
+ if (!this.config.pool && !this.config.uri) {
22
+ throw new Error("MysqlDriver: provide a `uri` (or an injected `pool`) to connect.");
23
+ }
24
+ this.pool = this.config.pool ?? mysql.createPool(this.config.uri);
25
+ this.drizzleDb = drizzle(this.pool, { schema: this.config.schema, mode: "default" });
26
+ if (this.config.autoCreate !== false && this.config.schema) {
27
+ for (const statement of generateMysqlDdl(this.config.schema)) {
28
+ await this.exec(statement);
29
+ }
30
+ }
31
+ this.connected = true;
32
+ }
33
+ async close() {
34
+ // Only end pools we created — an injected pool is the caller's.
35
+ if (this.pool && !this.config.pool) {
36
+ await this.pool.end();
37
+ }
38
+ this.pool = null;
39
+ this.drizzleDb = null;
40
+ this.connected = false;
41
+ }
42
+ isConnected() {
43
+ return this.connected;
44
+ }
45
+ // -------------------------------------------------------------------
46
+ // SqlExecutor — raw SQL for migrations and ad-hoc statements
47
+ // -------------------------------------------------------------------
48
+ /** Run one or more `;`-separated SQL statements. */
49
+ async exec(sql) {
50
+ const pool = this.requirePool();
51
+ for (const statement of splitSqlStatements(sql)) {
52
+ await pool.query(statement);
53
+ }
54
+ }
55
+ /** Run a query and return its rows. */
56
+ async all(sql) {
57
+ const [rows] = await this.requirePool().query(sql);
58
+ return rows;
59
+ }
60
+ requirePool() {
61
+ if (!this.pool) {
62
+ throw new Error("Database is not connected. Call connect() first.");
63
+ }
64
+ return this.pool;
65
+ }
66
+ /**
67
+ * The typed Drizzle instance for queries.
68
+ *
69
+ * Throws if the driver is not connected.
70
+ */
71
+ get db() {
72
+ if (!this.drizzleDb) {
73
+ throw new Error("Database is not connected. Call connect() first.");
74
+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,CAAC;YAClB,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACxE,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;CACJ"}
@@ -0,0 +1,5 @@
1
+ export { MysqlDriver } from "./driver.js";
2
+ export type { MysqlConfig } from "./driver.js";
3
+ export { MysqlProvider } from "./provider.js";
4
+ export { generateMysqlDdl } from "./ddl.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ export { MysqlDriver } from "./driver.js";
2
+ export { MysqlProvider } from "./provider.js";
3
+ export { generateMysqlDdl } from "./ddl.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { Provider, Application } from "@wild-framework/core";
2
+ import { type Migration } from "@wild-framework/database";
3
+ /**
4
+ * Registers a MySQL-backed database with the application.
5
+ *
6
+ * Static configuration (no-arg constructor requirement):
7
+ *
8
+ * ```ts
9
+ * MysqlProvider.uri = process.env.DATABASE_URL!;
10
+ * MysqlProvider.schema = { users };
11
+ * MysqlProvider.migrations = loadMigrations("./migrations");
12
+ * ```
13
+ *
14
+ * Connects on boot, creates tables from the schema, applies pending
15
+ * migrations, and closes on shutdown.
16
+ */
17
+ export declare class MysqlProvider implements Provider {
18
+ /** MySQL connection URI. */
19
+ static uri: string | undefined;
20
+ /** Drizzle schema object (tables). */
21
+ static schema: Record<string, unknown> | undefined;
22
+ /** Create tables from the schema at boot. Defaults to true. */
23
+ static autoCreate: boolean;
24
+ /** Migrations to apply (in order) after connecting. */
25
+ static migrations: Migration[];
26
+ register(app: Application): void;
27
+ boot(app: Application): Promise<void>;
28
+ shutdown(app: Application): Promise<void>;
29
+ }
30
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAElE,OAAO,EAA6B,KAAK,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAGrF;;;;;;;;;;;;;GAaG;AACH,qBAAa,aAAc,YAAW,QAAQ;IAC1C,4BAA4B;IAC5B,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,sCAAsC;IACtC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,CAAC;IACnD,+DAA+D;IAC/D,MAAM,CAAC,UAAU,UAAQ;IACzB,uDAAuD;IACvD,MAAM,CAAC,UAAU,EAAE,SAAS,EAAE,CAAM;IAEpC,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI;IAa1B,IAAI,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAarC,QAAQ,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAIlD"}
@@ -0,0 +1,53 @@
1
+ import { Container } from "@wild-framework/container";
2
+ import { Database, MigrationRunner } from "@wild-framework/database";
3
+ import { MysqlDriver } from "./driver.js";
4
+ /**
5
+ * Registers a MySQL-backed database with the application.
6
+ *
7
+ * Static configuration (no-arg constructor requirement):
8
+ *
9
+ * ```ts
10
+ * MysqlProvider.uri = process.env.DATABASE_URL!;
11
+ * MysqlProvider.schema = { users };
12
+ * MysqlProvider.migrations = loadMigrations("./migrations");
13
+ * ```
14
+ *
15
+ * Connects on boot, creates tables from the schema, applies pending
16
+ * migrations, and closes on shutdown.
17
+ */
18
+ export class MysqlProvider {
19
+ /** MySQL connection URI. */
20
+ static uri;
21
+ /** Drizzle schema object (tables). */
22
+ static schema;
23
+ /** Create tables from the schema at boot. Defaults to true. */
24
+ static autoCreate = true;
25
+ /** Migrations to apply (in order) after connecting. */
26
+ static migrations = [];
27
+ register(app) {
28
+ const container = app.resolve(Container);
29
+ const driver = new MysqlDriver({
30
+ uri: MysqlProvider.uri,
31
+ schema: MysqlProvider.schema,
32
+ autoCreate: MysqlProvider.autoCreate,
33
+ });
34
+ const database = new Database(driver);
35
+ container.singleton(Database, () => database);
36
+ }
37
+ async boot(app) {
38
+ const database = app.resolve(Database);
39
+ await database.connect();
40
+ if (MysqlProvider.migrations.length > 0) {
41
+ const driver = database.driver;
42
+ const applied = await new MigrationRunner(driver).migrate(MysqlProvider.migrations);
43
+ if (applied.length > 0) {
44
+ console.log(`[mysql] applied ${applied.length} migration(s): ${applied.join(", ")}`);
45
+ }
46
+ }
47
+ }
48
+ async shutdown(app) {
49
+ const database = app.resolve(Database);
50
+ await database.close();
51
+ }
52
+ }
53
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAkB,MAAM,0BAA0B,CAAC;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;;;;;;;GAaG;AACH,MAAM,O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K,CAAC,QAAQ,CAAC,GAAgB;QAC3B,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,CAAW,QAAQ,CAAC,CAAC;QACjD,MAAM,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC3B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@wild-framework/database-mysql",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "license": "MIT",
20
+ "author": "Sphah",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/KhandaSoftware/wild-framework.git"
24
+ },
25
+ "description": "MySQL driver for Wild Framework's database package (Drizzle + mysql2).",
26
+ "keywords": [
27
+ "wild",
28
+ "framework",
29
+ "drizzle",
30
+ "mysql",
31
+ "mysql2"
32
+ ],
33
+ "dependencies": {
34
+ "drizzle-orm": "^0.38.0",
35
+ "mysql2": "^3.11.0",
36
+ "@wild-framework/core": "0.2.0",
37
+ "@wild-framework/container": "0.2.0",
38
+ "@wild-framework/database": "0.2.0"
39
+ },
40
+ "devDependencies": {},
41
+ "scripts": {
42
+ "build": "tsc",
43
+ "clean": "rm -rf dist",
44
+ "test": "vitest run"
45
+ }
6
46
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.