wabe-postgres 0.5.1
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 +52 -0
- package/bunfig.toml +4 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.js +5313 -0
- package/package.json +32 -0
- package/utils/preload.ts +5 -0
- package/utils/testHelper.ts +124 -0
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wabe-postgres",
|
|
3
|
+
"version": "0.5.1",
|
|
4
|
+
"description": "PostgreSQL adapter for Wabe (official)",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"wabe",
|
|
10
|
+
"postgres",
|
|
11
|
+
"postgresql",
|
|
12
|
+
"database",
|
|
13
|
+
"adapter"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "bun --filter wabe-build build:package $(pwd)",
|
|
17
|
+
"check": "tsc --project $(pwd)/tsconfig.json",
|
|
18
|
+
"lint": "biome lint . --no-errors-on-unmatched --config-path=../../",
|
|
19
|
+
"ci": "bun check && bun lint $(pwd) && bun test src",
|
|
20
|
+
"format": "biome format --write . --config-path=../../"
|
|
21
|
+
},
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"p-retry": "5.1.2",
|
|
25
|
+
"pg": "8.16.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/pg": "8.11.11",
|
|
29
|
+
"wabe": "workspace:*",
|
|
30
|
+
"wabe-postgres-launcher": "workspace:*"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/utils/preload.ts
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { v4 as uuid } from 'uuid'
|
|
2
|
+
import { runDatabase } from 'wabe-postgres-launcher'
|
|
3
|
+
import { type ClassInterface, Wabe } from 'wabe'
|
|
4
|
+
import getPort from 'get-port'
|
|
5
|
+
import { PostgresAdapter } from '../src'
|
|
6
|
+
|
|
7
|
+
export const setupTests = async (
|
|
8
|
+
additionalClasses: ClassInterface<any>[] = [],
|
|
9
|
+
) => {
|
|
10
|
+
const databaseId = uuid()
|
|
11
|
+
|
|
12
|
+
const port = await getPort()
|
|
13
|
+
|
|
14
|
+
await runDatabase()
|
|
15
|
+
|
|
16
|
+
const wabe = new Wabe<any>({
|
|
17
|
+
isProduction: false,
|
|
18
|
+
rootKey:
|
|
19
|
+
'0uwFvUxM$ceFuF1aEtTtZMa7DUN2NZudqgY5ve5W*QCyb58cwMj9JeoaV@d#%29v&aJzswuudVU1%nAT+rxS0Bh&OkgBYc0PH18*',
|
|
20
|
+
database: {
|
|
21
|
+
adapter: new PostgresAdapter({
|
|
22
|
+
databaseUrl: 'postgresql://wabe:wabe@localhost:5432',
|
|
23
|
+
databaseName: databaseId,
|
|
24
|
+
}),
|
|
25
|
+
},
|
|
26
|
+
authentication: {
|
|
27
|
+
roles: ['Client', 'Client2', 'Client3', 'Admin'],
|
|
28
|
+
session: {
|
|
29
|
+
jwtSecret: 'dev',
|
|
30
|
+
cookieSession: true,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
port,
|
|
34
|
+
schema: {
|
|
35
|
+
classes: [
|
|
36
|
+
...additionalClasses,
|
|
37
|
+
{
|
|
38
|
+
name: 'Test',
|
|
39
|
+
fields: {
|
|
40
|
+
field1: { type: 'String' },
|
|
41
|
+
int: { type: 'Int' },
|
|
42
|
+
array: { type: 'Array', typeValue: 'String' },
|
|
43
|
+
date: { type: 'Date' },
|
|
44
|
+
enum: { type: 'AuthenticationProvider' },
|
|
45
|
+
object: {
|
|
46
|
+
type: 'Object',
|
|
47
|
+
object: {
|
|
48
|
+
name: 'Object',
|
|
49
|
+
fields: {
|
|
50
|
+
array: {
|
|
51
|
+
type: 'Array',
|
|
52
|
+
typeValue: 'Object',
|
|
53
|
+
object: {
|
|
54
|
+
name: 'SubObject',
|
|
55
|
+
fields: {
|
|
56
|
+
string: {
|
|
57
|
+
type: 'String',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: 'User',
|
|
69
|
+
fields: {
|
|
70
|
+
name: { type: 'String' },
|
|
71
|
+
age: { type: 'Int' },
|
|
72
|
+
isAdmin: { type: 'Boolean', defaultValue: false },
|
|
73
|
+
floatValue: { type: 'Float' },
|
|
74
|
+
birthDate: { type: 'Date' },
|
|
75
|
+
arrayValue: {
|
|
76
|
+
type: 'Array',
|
|
77
|
+
typeValue: 'String',
|
|
78
|
+
},
|
|
79
|
+
test: { type: 'TestScalar' },
|
|
80
|
+
},
|
|
81
|
+
searchableFields: ['email'],
|
|
82
|
+
permissions: {
|
|
83
|
+
create: {
|
|
84
|
+
requireAuthentication: false,
|
|
85
|
+
},
|
|
86
|
+
delete: {
|
|
87
|
+
requireAuthentication: true,
|
|
88
|
+
},
|
|
89
|
+
update: {
|
|
90
|
+
requireAuthentication: false,
|
|
91
|
+
},
|
|
92
|
+
read: {
|
|
93
|
+
requireAuthentication: false,
|
|
94
|
+
},
|
|
95
|
+
acl: async (hookObject) => {
|
|
96
|
+
await hookObject.addACL('users', {
|
|
97
|
+
userId: hookObject.object?.id,
|
|
98
|
+
read: true,
|
|
99
|
+
write: true,
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
await hookObject.addACL('roles', null)
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
scalars: [
|
|
108
|
+
{
|
|
109
|
+
name: 'TestScalar',
|
|
110
|
+
description: 'Test scalar',
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
await wabe.start()
|
|
117
|
+
|
|
118
|
+
return { wabe, port }
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export const closeTests = async (wabe: Wabe<any>) => {
|
|
122
|
+
await wabe.controllers.database.adapter?.close()
|
|
123
|
+
await wabe.close()
|
|
124
|
+
}
|