@manablox/db 0.2.0 → 0.4.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.
Files changed (61) hide show
  1. package/dist/index-BLAkQMJT.d.ts +877 -0
  2. package/dist/index-DrNMGM9N.d.ts +5193 -0
  3. package/dist/index.d.ts +123 -0
  4. package/dist/index.js +60 -0
  5. package/dist/repositories-pz4NeWaF.js +1928 -0
  6. package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
  7. package/dist/schema-Dm3RcBst.js +648 -0
  8. package/dist/schema.d.ts +2 -0
  9. package/dist/schema.js +2 -0
  10. package/dist/testing.d.ts +77 -0
  11. package/dist/testing.js +217 -0
  12. package/migrations/0009_audit-log.sql +40 -0
  13. package/migrations/0010_notifications-approvals.sql +45 -0
  14. package/migrations/meta/0009_snapshot.json +3192 -0
  15. package/migrations/meta/0010_snapshot.json +3574 -0
  16. package/migrations/meta/_journal.json +14 -0
  17. package/package.json +18 -10
  18. package/drizzle.config.ts +0 -11
  19. package/src/bootstrap.ts +0 -13
  20. package/src/cli/create-db.ts +0 -30
  21. package/src/cli/migrate.ts +0 -17
  22. package/src/client.ts +0 -44
  23. package/src/columns.ts +0 -39
  24. package/src/errors.ts +0 -50
  25. package/src/index.ts +0 -19
  26. package/src/migrate.ts +0 -21
  27. package/src/pagination.ts +0 -52
  28. package/src/query.ts +0 -213
  29. package/src/repositories/asset-usage.ts +0 -166
  30. package/src/repositories/asset.ts +0 -181
  31. package/src/repositories/content-type.ts +0 -116
  32. package/src/repositories/content.ts +0 -811
  33. package/src/repositories/index.ts +0 -40
  34. package/src/repositories/menu.ts +0 -235
  35. package/src/repositories/role.ts +0 -85
  36. package/src/repositories/space.ts +0 -83
  37. package/src/repositories/user.ts +0 -280
  38. package/src/repositories/webhook.ts +0 -46
  39. package/src/repositories/workflow.ts +0 -306
  40. package/src/schema/assets.ts +0 -108
  41. package/src/schema/auth.ts +0 -166
  42. package/src/schema/content-types.ts +0 -31
  43. package/src/schema/content.ts +0 -133
  44. package/src/schema/index.ts +0 -38
  45. package/src/schema/menus.ts +0 -61
  46. package/src/schema/relations.ts +0 -64
  47. package/src/schema/spaces.ts +0 -20
  48. package/src/schema/webhooks.ts +0 -46
  49. package/src/schema/workflows.ts +0 -92
  50. package/src/testing-fixtures.ts +0 -139
  51. package/src/testing.ts +0 -105
  52. package/test/asset-usage.test.ts +0 -101
  53. package/test/menu.test.ts +0 -126
  54. package/test/publish.test.ts +0 -130
  55. package/test/query.test.ts +0 -170
  56. package/test/role.test.ts +0 -81
  57. package/test/tree.test.ts +0 -188
  58. package/test/user.test.ts +0 -126
  59. package/test/webhook.test.ts +0 -48
  60. package/tsconfig.json +0 -4
  61. package/vitest.config.ts +0 -10
package/test/user.test.ts DELETED
@@ -1,126 +0,0 @@
1
- import { eq } from 'drizzle-orm';
2
- import { afterAll, beforeAll, describe, expect, it } from 'vitest';
3
- import { accounts, memberships, sessions } from '../src/schema/index.js';
4
- import { createRepositoryContext, type RepositoryTestContext } from '../src/testing.js';
5
-
6
- let ctx: RepositoryTestContext;
7
-
8
- beforeAll(async () => {
9
- ctx = await createRepositoryContext('user');
10
- });
11
- afterAll(async () => {
12
- await ctx?.close();
13
- });
14
-
15
- const stamp = () => Date.now().toString(36) + Math.random().toString(36).slice(2, 6);
16
-
17
- describe('UserRepository.create', () => {
18
- it('writes the credential the way better-auth 1.7 looks it up', async () => {
19
- const user = await ctx.repos.users.create({
20
- name: 'Sam',
21
- email: `sam-${stamp()}@example.com`,
22
- role: 'editor',
23
- passwordHash: '$argon2id$hash',
24
- });
25
-
26
- const rows = await ctx.handle.db.select().from(accounts).where(eq(accounts.userId, user.id));
27
- expect(rows).toHaveLength(1);
28
- // Sign-in matches on all three; a row missing the issuer is invisible to it.
29
- expect(rows[0]).toMatchObject({
30
- providerId: 'credential',
31
- issuer: 'local:credential',
32
- accountId: user.id,
33
- password: '$argon2id$hash',
34
- });
35
- });
36
-
37
- it('refuses a second account on the same email', async () => {
38
- const email = `dup-${stamp()}@example.com`;
39
- const make = () =>
40
- ctx.repos.users.create({ name: 'A', email, role: 'editor', passwordHash: 'x' });
41
- await make();
42
- await expect(make()).rejects.toMatchObject({ cause: { code: '23505' } });
43
- });
44
- });
45
-
46
- describe('UserRepository passwords and sessions', () => {
47
- it('replaces the credential rather than adding a second one', async () => {
48
- const user = await ctx.repos.users.create({
49
- name: 'Pat',
50
- email: `pat-${stamp()}@example.com`,
51
- role: 'editor',
52
- passwordHash: 'old',
53
- });
54
- await ctx.repos.users.setPasswordHash(user.id, 'new');
55
-
56
- const rows = await ctx.handle.db.select().from(accounts).where(eq(accounts.userId, user.id));
57
- expect(rows).toHaveLength(1);
58
- expect(rows[0]?.password).toBe('new');
59
- });
60
-
61
- it('revokes every session of one user and nobody else', async () => {
62
- const [a, b] = await Promise.all(
63
- ['a', 'b'].map((n) =>
64
- ctx.repos.users.create({
65
- name: n,
66
- email: `${n}-${stamp()}@example.com`,
67
- role: 'editor',
68
- passwordHash: 'x',
69
- }),
70
- ),
71
- );
72
- const expiresAt = new Date(Date.now() + 60_000);
73
- await ctx.handle.db.insert(sessions).values([
74
- { userId: a!.id, token: `a1-${stamp()}`, expiresAt },
75
- { userId: a!.id, token: `a2-${stamp()}`, expiresAt },
76
- { userId: b!.id, token: `b1-${stamp()}`, expiresAt },
77
- ]);
78
-
79
- await ctx.repos.users.revokeSessions(a!.id);
80
-
81
- expect(
82
- await ctx.handle.db.select().from(sessions).where(eq(sessions.userId, a!.id)),
83
- ).toHaveLength(0);
84
- expect(
85
- await ctx.handle.db.select().from(sessions).where(eq(sessions.userId, b!.id)),
86
- ).toHaveLength(1);
87
- });
88
- });
89
-
90
- describe('UserRepository.delete', () => {
91
- it('takes the credential and the memberships with it', async () => {
92
- const user = await ctx.repos.users.create({
93
- name: 'Gone',
94
- email: `gone-${stamp()}@example.com`,
95
- role: 'editor',
96
- passwordHash: 'x',
97
- });
98
- await ctx.repos.users.grant(user.id, ctx.spaceId, 'viewer');
99
- expect(await ctx.repos.users.membershipsWithSpaces(user.id)).toMatchObject([
100
- { role: 'viewer', space: { id: ctx.spaceId } },
101
- ]);
102
-
103
- await ctx.repos.users.delete(user.id);
104
-
105
- expect(await ctx.repos.users.findById(user.id)).toBeNull();
106
- expect(
107
- await ctx.handle.db.select().from(accounts).where(eq(accounts.userId, user.id)),
108
- ).toHaveLength(0);
109
- expect(
110
- await ctx.handle.db.select().from(memberships).where(eq(memberships.userId, user.id)),
111
- ).toHaveLength(0);
112
- });
113
- });
114
-
115
- describe('UserRepository.countByRole', () => {
116
- it('counts the instance role', async () => {
117
- const before = await ctx.repos.users.countByRole('superadmin');
118
- await ctx.repos.users.create({
119
- name: 'Root',
120
- email: `root-${stamp()}@example.com`,
121
- role: 'superadmin',
122
- passwordHash: 'x',
123
- });
124
- expect(await ctx.repos.users.countByRole('superadmin')).toBe(before + 1);
125
- });
126
- });
@@ -1,48 +0,0 @@
1
- import { afterAll, beforeAll, describe, expect, it } from 'vitest';
2
- import { webhooks } from '../src/schema/index.js';
3
- import { createRepositoryContext, type RepositoryTestContext } from '../src/testing.js';
4
-
5
- let ctx: RepositoryTestContext;
6
-
7
- beforeAll(async () => {
8
- ctx = await createRepositoryContext('webhook');
9
- });
10
- afterAll(async () => {
11
- await ctx?.close();
12
- });
13
-
14
- describe('webhooks', () => {
15
- it('lists only the switched-on webhooks of a space and logs deliveries', async () => {
16
- const [on, off] = await ctx.handle.db
17
- .insert(webhooks)
18
- .values([
19
- { spaceId: ctx.spaceId, name: 'On', url: 'https://on.test', events: [] },
20
- { spaceId: ctx.spaceId, name: 'Off', url: 'https://off.test', events: [], enabled: false },
21
- ])
22
- .returning();
23
-
24
- const enabled = await ctx.repos.webhooks.findEnabled(ctx.spaceId);
25
- expect(enabled.map((row) => row.id)).toEqual([on?.id]);
26
- expect(await ctx.repos.webhooks.findById(off?.id as string)).toMatchObject({ enabled: false });
27
-
28
- await ctx.repos.webhooks.recordDelivery({
29
- webhookId: on?.id as string,
30
- event: 'content.published',
31
- payload: { id: 'x' },
32
- status: 200,
33
- error: null,
34
- });
35
- await ctx.repos.webhooks.recordDelivery({
36
- webhookId: on?.id as string,
37
- event: 'content.published',
38
- payload: { id: 'y' },
39
- status: null,
40
- error: 'ECONNREFUSED',
41
- });
42
- const log = await ctx.repos.webhooks.deliveries(on?.id as string);
43
- expect(log.map((row) => [row.status, row.error])).toEqual([
44
- [200, null],
45
- [null, 'ECONNREFUSED'],
46
- ]);
47
- });
48
- });
package/tsconfig.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "extends": "@manablox/config-typescript/library.json",
3
- "include": ["src", "test", "drizzle.config.ts"]
4
- }
package/vitest.config.ts DELETED
@@ -1,10 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- environment: 'node',
6
- include: ['test/**/*.test.ts'],
7
- testTimeout: 60_000,
8
- hookTimeout: 60_000,
9
- },
10
- });