@manablox/db 0.1.0 → 0.3.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/README.md +21 -0
- package/dist/index-Cyf_N5K3.d.ts +658 -0
- package/dist/index-rZ24t-Ln.d.ts +4338 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.js +60 -0
- package/dist/repositories-DYjzuuF6.js +1533 -0
- package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/schema-Bb4p16Yz.js +539 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.js +2 -0
- package/dist/testing.d.ts +77 -0
- package/dist/testing.js +217 -0
- package/migrations/0005_menus.sql +44 -0
- package/migrations/0006_roles.sql +13 -0
- package/migrations/0007_apikey-permissions.sql +4 -0
- package/migrations/0008_workflows.sql +49 -0
- package/migrations/meta/0005_snapshot.json +2504 -0
- package/migrations/meta/0006_snapshot.json +2605 -0
- package/migrations/meta/0007_snapshot.json +2605 -0
- package/migrations/meta/0008_snapshot.json +2986 -0
- package/migrations/meta/_journal.json +28 -0
- package/package.json +22 -9
- package/drizzle.config.ts +0 -11
- package/src/bootstrap.ts +0 -13
- package/src/cli/migrate.ts +0 -24
- package/src/client.ts +0 -37
- package/src/columns.ts +0 -39
- package/src/index.ts +0 -13
- package/src/query.ts +0 -217
- package/src/repositories/asset-usage.ts +0 -166
- package/src/repositories/asset.ts +0 -189
- package/src/repositories/content-type.ts +0 -116
- package/src/repositories/content.ts +0 -758
- package/src/repositories/index.ts +0 -28
- package/src/repositories/space.ts +0 -78
- package/src/repositories/user.ts +0 -134
- package/src/schema.ts +0 -513
- package/test/asset-usage.test.ts +0 -101
- package/test/helpers.ts +0 -153
- package/test/publish.test.ts +0 -102
- package/test/query.test.ts +0 -140
- package/test/tree.test.ts +0 -188
- package/tsconfig.json +0 -4
- package/vitest.config.ts +0 -12
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { A as menusRelations, B as accounts, C as spaces, D as contentsRelations, E as assetsRelations, F as menus, G as users, H as memberships, I as contentTypes, J as assetVariants, K as verifications, L as contentVersions, M as spacesRelations, N as usersRelations, O as membershipsRelations, P as menuItems, R as contents, S as webhooks, T as assetVariantsRelations, U as roles, V as apikeys, W as sessions, Y as assets, _ as index_d_exports, a as ContentRow, b as workflows, c as MembershipRow, d as PushSubscriptionRow, f as RoleRow, g as WorkflowRunRow, h as WorkflowRow, i as ContentInsert, j as rolesRelations, k as menuItemsRelations, l as MenuItemRow, m as UserRow, n as AssetUsageRow, o as ContentTypeRow, p as SpaceRow, q as assetUsages, r as AssetVariantRow, s as ContentVersionRow, t as AssetRow, u as MenuRow, v as pushSubscriptions, w as assetUsagesRelations, x as webhookDeliveries, y as workflowRuns, z as publishedContents } from "./index-rZ24t-Ln.js";
|
|
2
|
+
import { A as AssetRepository, B as buildContentWhere, C as ContentRepository, D as buildTree, E as TreeNode, F as ContentSort, G as Executor, H as Database, I as ContentTable, J as createDatabase, K as Sql, L as FieldFilter, M as Paginated, N as paginate, O as AssetUsageRepository, P as ContentFilter, R as Pagination, S as ContentTypeRepository, T as SQL, U as DatabaseHandle, V as buildOrderBy, W as DatabaseOptions, _ as MenuItemInput, a as WorkflowRunCreateData, b as MenuWriteData, c as WebhookDeliveryRow, d as SpaceRole, f as UserCreateData, g as SpaceWriteData, h as SpaceRepository, i as WorkflowRepository, j as AssetWriteData, k as AssetFilter, l as WebhookRepository, m as UserUpdateData, n as createRepositories, o as WorkflowWriteData, p as UserRepository, q as Transaction, r as RUNS_KEPT_PER_WORKFLOW, s as WebhookDeliveryData, t as Repositories, u as WebhookRow, v as MenuItemNode, w as ContentWriteData, x as ResolvedMenuItem, y as MenuRepository, z as PgColumn } from "./index-Cyf_N5K3.js";
|
|
3
|
+
import { ErrorKey } from "@manablox/core";
|
|
4
|
+
//#region src/bootstrap.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Extensions the schema depends on. Run before the generated migrations, which
|
|
7
|
+
* reference `ltree` columns and `pg_trgm` operator classes.
|
|
8
|
+
*/
|
|
9
|
+
export declare function applyBootstrapSql(sql: Sql): Promise<void>;
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/columns.d.ts
|
|
12
|
+
/**
|
|
13
|
+
* `ltree` — the materialised ancestor path of a content node. A subtree move is one
|
|
14
|
+
* `UPDATE ... SET path = :newParent || subpath(path, nlevel(:oldParent))`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const ltree: {
|
|
17
|
+
(): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
18
|
+
name: "";
|
|
19
|
+
dataType: 'custom';
|
|
20
|
+
columnType: 'PgCustomColumn';
|
|
21
|
+
data: string;
|
|
22
|
+
driverParam: string;
|
|
23
|
+
enumValues: undefined;
|
|
24
|
+
}>;
|
|
25
|
+
<TConfig extends Record<string, any> & unknown>(fieldConfig?: TConfig | undefined): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
26
|
+
name: "";
|
|
27
|
+
dataType: 'custom';
|
|
28
|
+
columnType: 'PgCustomColumn';
|
|
29
|
+
data: string;
|
|
30
|
+
driverParam: string;
|
|
31
|
+
enumValues: undefined;
|
|
32
|
+
}>;
|
|
33
|
+
<TName extends string>(dbName: TName, fieldConfig?: unknown): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
34
|
+
name: TName;
|
|
35
|
+
dataType: 'custom';
|
|
36
|
+
columnType: 'PgCustomColumn';
|
|
37
|
+
data: string;
|
|
38
|
+
driverParam: string;
|
|
39
|
+
enumValues: undefined;
|
|
40
|
+
}>;
|
|
41
|
+
};
|
|
42
|
+
/** `tsvector` — generated from `title` + `search_text`, never written directly. */
|
|
43
|
+
export declare const tsvector: {
|
|
44
|
+
(): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
45
|
+
name: "";
|
|
46
|
+
dataType: 'custom';
|
|
47
|
+
columnType: 'PgCustomColumn';
|
|
48
|
+
data: string;
|
|
49
|
+
driverParam: string;
|
|
50
|
+
enumValues: undefined;
|
|
51
|
+
}>;
|
|
52
|
+
<TConfig extends Record<string, any> & unknown>(fieldConfig?: TConfig | undefined): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
53
|
+
name: "";
|
|
54
|
+
dataType: 'custom';
|
|
55
|
+
columnType: 'PgCustomColumn';
|
|
56
|
+
data: string;
|
|
57
|
+
driverParam: string;
|
|
58
|
+
enumValues: undefined;
|
|
59
|
+
}>;
|
|
60
|
+
<TName extends string>(dbName: TName, fieldConfig?: unknown): import("drizzle-orm/pg-core").PgCustomColumnBuilder<{
|
|
61
|
+
name: TName;
|
|
62
|
+
dataType: 'custom';
|
|
63
|
+
columnType: 'PgCustomColumn';
|
|
64
|
+
data: string;
|
|
65
|
+
driverParam: string;
|
|
66
|
+
enumValues: undefined;
|
|
67
|
+
}>;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* ltree labels accept only `[A-Za-z0-9_]`, so UUID hyphens are swapped for underscores.
|
|
71
|
+
* The transform is total and reversible.
|
|
72
|
+
*/
|
|
73
|
+
export declare const idToLabel: (id: string) => string;
|
|
74
|
+
export declare const labelToId: (label: string) => string;
|
|
75
|
+
/** Builds the path of a node from its ancestors' ids (root first) plus its own. */
|
|
76
|
+
export declare const buildPath: (ancestorIds: string[], selfId: string) => string;
|
|
77
|
+
/** Splits a stored path back into ids, root first, self last. */
|
|
78
|
+
export declare const parsePath: (path: string) => string[];
|
|
79
|
+
export declare const pathDepth: (path: string) => number;
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/errors.d.ts
|
|
82
|
+
/**
|
|
83
|
+
* Postgres reports a unique-constraint violation as SQLSTATE `23505` with the constraint
|
|
84
|
+
* name in the message. Drizzle wraps the driver error, so the code and the message sit on
|
|
85
|
+
* `cause`, while the outer message is only ever "Failed query: insert into …".
|
|
86
|
+
*/
|
|
87
|
+
export declare function isUniqueViolation(error: unknown, constraint: string): boolean;
|
|
88
|
+
export interface UniqueViolationMapping {
|
|
89
|
+
/** The constraint name, or a distinctive part of it. */
|
|
90
|
+
constraint: string;
|
|
91
|
+
/** The detail reported for the field, e.g. `content.slug.duplicate`. */
|
|
92
|
+
key: ErrorKey;
|
|
93
|
+
path?: (string | number)[];
|
|
94
|
+
params?: Record<string, unknown>;
|
|
95
|
+
/** The error's own key. */
|
|
96
|
+
errorKey: ErrorKey;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Turns a unique violation on one constraint into the validation error the client would
|
|
100
|
+
* have received had the check run before the write, and rethrows anything else untouched.
|
|
101
|
+
* Use as `.catch((error) => rethrowUniqueViolation(error, { … }))`.
|
|
102
|
+
*/
|
|
103
|
+
export declare function rethrowUniqueViolation(error: unknown, mapping: UniqueViolationMapping): never;
|
|
104
|
+
/**
|
|
105
|
+
* A preset for one constraint: `const taken = uniqueViolation({ … })` once beside the
|
|
106
|
+
* service, then `.catch(taken({ machineName }))` on every write that can trip it. The
|
|
107
|
+
* params are the only part that differs per call, so they are the only argument left.
|
|
108
|
+
*/
|
|
109
|
+
export declare function uniqueViolation(preset: Omit<UniqueViolationMapping, 'params'>): (params: Record<string, unknown>) => (error: unknown) => never;
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/migrate.d.ts
|
|
112
|
+
/** The SQL files shipped with this package, next to `src/`. */
|
|
113
|
+
export declare const MIGRATIONS_FOLDER: string;
|
|
114
|
+
/**
|
|
115
|
+
* Brings a database up to the schema this version of the package expects.
|
|
116
|
+
*
|
|
117
|
+
* The same call the compose stack's `migrate` service and the `manablox migrate` CLI
|
|
118
|
+
* make, so an instance run from a dependency and one run from the repository apply the
|
|
119
|
+
* same files in the same order. Idempotent: drizzle records what it has applied.
|
|
120
|
+
*/
|
|
121
|
+
export declare function runMigrations(handle: DatabaseHandle): Promise<void>;
|
|
122
|
+
//#endregion
|
|
123
|
+
export { AssetFilter, AssetRepository, AssetRow, AssetUsageRepository, AssetUsageRow, AssetVariantRow, AssetWriteData, ContentFilter, ContentInsert, ContentRepository, ContentRow, ContentSort, ContentTable, ContentTypeRepository, ContentTypeRow, ContentVersionRow, ContentWriteData, Database, DatabaseHandle, DatabaseOptions, Executor, FieldFilter, MembershipRow, MenuItemInput, MenuItemNode, MenuItemRow, MenuRepository, MenuRow, MenuWriteData, Paginated, Pagination, type PgColumn, PushSubscriptionRow, RUNS_KEPT_PER_WORKFLOW, Repositories, ResolvedMenuItem, RoleRow, type SQL, SpaceRepository, SpaceRole, SpaceRow, SpaceWriteData, Sql, Transaction, TreeNode, UserCreateData, UserRepository, UserRow, UserUpdateData, WebhookDeliveryData, WebhookDeliveryRow, WebhookRepository, WebhookRow, WorkflowRepository, WorkflowRow, WorkflowRunCreateData, WorkflowRunRow, WorkflowWriteData, accounts, apikeys, assetUsages, assetUsagesRelations, assetVariants, assetVariantsRelations, assets, assetsRelations, buildContentWhere, buildOrderBy, buildTree, contentTypes, contentVersions, contents, contentsRelations, createDatabase, createRepositories, memberships, membershipsRelations, menuItems, menuItemsRelations, menus, menusRelations, paginate, publishedContents, pushSubscriptions, roles, rolesRelations, index_d_exports as schema, sessions, spaces, spacesRelations, users, usersRelations, verifications, webhookDeliveries, webhooks, workflowRuns, workflows };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { _ as applyBootstrapSql, a as UserRepository, c as ContentTypeRepository, d as AssetUsageRepository, f as AssetRepository, g as createDatabase, h as paginate, i as WebhookRepository, l as ContentRepository, m as buildOrderBy, n as RUNS_KEPT_PER_WORKFLOW, o as SpaceRepository, p as buildContentWhere, r as WorkflowRepository, s as MenuRepository, t as createRepositories, u as buildTree } from "./repositories-DYjzuuF6.js";
|
|
2
|
+
import { A as contentVersions, B as tsvector, C as roles, D as assetUsages, E as verifications, F as idToLabel, I as labelToId, L as ltree, M as publishedContents, N as spaces, O as assetVariants, P as buildPath, R as parsePath, S as memberships, T as users, _ as menuItems, a as webhookDeliveries, b as accounts, c as assetVariantsRelations, d as membershipsRelations, f as menuItemsRelations, g as usersRelations, h as spacesRelations, i as workflows, j as contents, k as assets, l as assetsRelations, m as rolesRelations, n as pushSubscriptions, o as webhooks, p as menusRelations, r as workflowRuns, s as assetUsagesRelations, t as schema_exports, u as contentsRelations, v as menus, w as sessions, x as apikeys, y as contentTypes, z as pathDepth } from "./schema-Bb4p16Yz.js";
|
|
3
|
+
import { ManabloxError } from "@manablox/core";
|
|
4
|
+
import { dirname, resolve } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { migrate } from "drizzle-orm/postgres-js/migrator";
|
|
7
|
+
//#region src/errors.ts
|
|
8
|
+
/**
|
|
9
|
+
* Postgres reports a unique-constraint violation as SQLSTATE `23505` with the constraint
|
|
10
|
+
* name in the message. Drizzle wraps the driver error, so the code and the message sit on
|
|
11
|
+
* `cause`, while the outer message is only ever "Failed query: insert into …".
|
|
12
|
+
*/
|
|
13
|
+
function isUniqueViolation(error, constraint) {
|
|
14
|
+
const cause = error?.cause;
|
|
15
|
+
const code = error?.code ?? cause?.code;
|
|
16
|
+
const detail = `${cause?.message ?? ""} ${error?.message ?? ""}`;
|
|
17
|
+
return code === "23505" && detail.includes(constraint);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Turns a unique violation on one constraint into the validation error the client would
|
|
21
|
+
* have received had the check run before the write, and rethrows anything else untouched.
|
|
22
|
+
* Use as `.catch((error) => rethrowUniqueViolation(error, { … }))`.
|
|
23
|
+
*/
|
|
24
|
+
function rethrowUniqueViolation(error, mapping) {
|
|
25
|
+
if (!isUniqueViolation(error, mapping.constraint)) throw error;
|
|
26
|
+
const detail = {
|
|
27
|
+
key: mapping.key,
|
|
28
|
+
...mapping.path ? { path: mapping.path } : {},
|
|
29
|
+
...mapping.params ? { params: mapping.params } : {}
|
|
30
|
+
};
|
|
31
|
+
throw ManabloxError.validation([detail], mapping.errorKey);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A preset for one constraint: `const taken = uniqueViolation({ … })` once beside the
|
|
35
|
+
* service, then `.catch(taken({ machineName }))` on every write that can trip it. The
|
|
36
|
+
* params are the only part that differs per call, so they are the only argument left.
|
|
37
|
+
*/
|
|
38
|
+
function uniqueViolation(preset) {
|
|
39
|
+
return (params) => (error) => rethrowUniqueViolation(error, {
|
|
40
|
+
...preset,
|
|
41
|
+
params
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region src/migrate.ts
|
|
46
|
+
/** The SQL files shipped with this package, next to `src/`. */
|
|
47
|
+
const MIGRATIONS_FOLDER = resolve(dirname(fileURLToPath(import.meta.url)), "../migrations");
|
|
48
|
+
/**
|
|
49
|
+
* Brings a database up to the schema this version of the package expects.
|
|
50
|
+
*
|
|
51
|
+
* The same call the compose stack's `migrate` service and the `manablox migrate` CLI
|
|
52
|
+
* make, so an instance run from a dependency and one run from the repository apply the
|
|
53
|
+
* same files in the same order. Idempotent: drizzle records what it has applied.
|
|
54
|
+
*/
|
|
55
|
+
async function runMigrations(handle) {
|
|
56
|
+
await applyBootstrapSql(handle.sql);
|
|
57
|
+
await migrate(handle.db, { migrationsFolder: MIGRATIONS_FOLDER });
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { AssetRepository, AssetUsageRepository, ContentRepository, ContentTypeRepository, MIGRATIONS_FOLDER, MenuRepository, RUNS_KEPT_PER_WORKFLOW, SpaceRepository, UserRepository, WebhookRepository, WorkflowRepository, accounts, apikeys, applyBootstrapSql, assetUsages, assetUsagesRelations, assetVariants, assetVariantsRelations, assets, assetsRelations, buildContentWhere, buildOrderBy, buildPath, buildTree, contentTypes, contentVersions, contents, contentsRelations, createDatabase, createRepositories, idToLabel, isUniqueViolation, labelToId, ltree, memberships, membershipsRelations, menuItems, menuItemsRelations, menus, menusRelations, paginate, parsePath, pathDepth, publishedContents, pushSubscriptions, rethrowUniqueViolation, roles, rolesRelations, runMigrations, schema_exports as schema, sessions, spaces, spacesRelations, tsvector, uniqueViolation, users, usersRelations, verifications, webhookDeliveries, webhooks, workflowRuns, workflows };
|