@manablox/db 0.2.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.
Files changed (56) hide show
  1. package/dist/index-Cyf_N5K3.d.ts +658 -0
  2. package/dist/index-rZ24t-Ln.d.ts +4338 -0
  3. package/dist/index.d.ts +123 -0
  4. package/dist/index.js +60 -0
  5. package/dist/repositories-DYjzuuF6.js +1533 -0
  6. package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
  7. package/dist/schema-Bb4p16Yz.js +539 -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/package.json +18 -10
  13. package/drizzle.config.ts +0 -11
  14. package/src/bootstrap.ts +0 -13
  15. package/src/cli/create-db.ts +0 -30
  16. package/src/cli/migrate.ts +0 -17
  17. package/src/client.ts +0 -44
  18. package/src/columns.ts +0 -39
  19. package/src/errors.ts +0 -50
  20. package/src/index.ts +0 -19
  21. package/src/migrate.ts +0 -21
  22. package/src/pagination.ts +0 -52
  23. package/src/query.ts +0 -213
  24. package/src/repositories/asset-usage.ts +0 -166
  25. package/src/repositories/asset.ts +0 -181
  26. package/src/repositories/content-type.ts +0 -116
  27. package/src/repositories/content.ts +0 -811
  28. package/src/repositories/index.ts +0 -40
  29. package/src/repositories/menu.ts +0 -235
  30. package/src/repositories/role.ts +0 -85
  31. package/src/repositories/space.ts +0 -83
  32. package/src/repositories/user.ts +0 -280
  33. package/src/repositories/webhook.ts +0 -46
  34. package/src/repositories/workflow.ts +0 -306
  35. package/src/schema/assets.ts +0 -108
  36. package/src/schema/auth.ts +0 -166
  37. package/src/schema/content-types.ts +0 -31
  38. package/src/schema/content.ts +0 -133
  39. package/src/schema/index.ts +0 -38
  40. package/src/schema/menus.ts +0 -61
  41. package/src/schema/relations.ts +0 -64
  42. package/src/schema/spaces.ts +0 -20
  43. package/src/schema/webhooks.ts +0 -46
  44. package/src/schema/workflows.ts +0 -92
  45. package/src/testing-fixtures.ts +0 -139
  46. package/src/testing.ts +0 -105
  47. package/test/asset-usage.test.ts +0 -101
  48. package/test/menu.test.ts +0 -126
  49. package/test/publish.test.ts +0 -130
  50. package/test/query.test.ts +0 -170
  51. package/test/role.test.ts +0 -81
  52. package/test/tree.test.ts +0 -188
  53. package/test/user.test.ts +0 -126
  54. package/test/webhook.test.ts +0 -48
  55. package/tsconfig.json +0 -4
  56. 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
- });