wabe-postgres 0.5.1 → 0.5.2
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 +113 -39
- package/package.json +32 -30
- package/src/index.test.ts +2115 -0
- package/src/index.ts +752 -0
- package/tsconfig.json +31 -0
- package/utils/preload.ts +1 -1
- package/utils/testHelper.ts +110 -108
- package/bunfig.toml +0 -4
- package/dist/index.d.ts +0 -74
- package/dist/index.js +0 -5313
package/tsconfig.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Environment setup & latest features
|
|
4
|
+
"lib": ["ESNext"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "Preserve",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
|
|
11
|
+
// Bundler mode
|
|
12
|
+
"moduleResolution": "bundler",
|
|
13
|
+
"allowImportingTsExtensions": true,
|
|
14
|
+
"verbatimModuleSyntax": false,
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
|
|
17
|
+
// Best practices
|
|
18
|
+
"strict": true,
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
"noFallthroughCasesInSwitch": true,
|
|
21
|
+
"noUncheckedIndexedAccess": true,
|
|
22
|
+
"noImplicitOverride": true,
|
|
23
|
+
|
|
24
|
+
// Some stricter flags (disabled by default)
|
|
25
|
+
"noUnusedLocals": false,
|
|
26
|
+
"noUnusedParameters": false,
|
|
27
|
+
"noPropertyAccessFromIndexSignature": false,
|
|
28
|
+
"baseUrl": "."
|
|
29
|
+
},
|
|
30
|
+
"exclude": ["node_modules", "dist", "**/*.test.ts"]
|
|
31
|
+
}
|
package/utils/preload.ts
CHANGED
package/utils/testHelper.ts
CHANGED
|
@@ -4,121 +4,123 @@ import { type ClassInterface, Wabe } from 'wabe'
|
|
|
4
4
|
import getPort from 'get-port'
|
|
5
5
|
import { PostgresAdapter } from '../src'
|
|
6
6
|
|
|
7
|
-
export const setupTests = async (
|
|
8
|
-
|
|
9
|
-
) => {
|
|
10
|
-
const databaseId = uuid()
|
|
7
|
+
export const setupTests = async (additionalClasses: ClassInterface<any>[] = []) => {
|
|
8
|
+
const databaseId = uuid()
|
|
11
9
|
|
|
12
|
-
|
|
10
|
+
const port = await getPort()
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
await runDatabase()
|
|
15
13
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
14
|
+
const wabe = new Wabe<any>({
|
|
15
|
+
isProduction: false,
|
|
16
|
+
rootKey:
|
|
17
|
+
'0uwFvUxM$ceFuF1aEtTtZMa7DUN2NZudqgY5ve5W*QCyb58cwMj9JeoaV@d#%29v&aJzswuudVU1%nAT+rxS0Bh&OkgBYc0PH18*',
|
|
18
|
+
database: {
|
|
19
|
+
adapter: new PostgresAdapter({
|
|
20
|
+
databaseUrl: 'postgresql://wabe:wabe@localhost:5432',
|
|
21
|
+
databaseName: databaseId,
|
|
22
|
+
}),
|
|
23
|
+
},
|
|
24
|
+
authentication: {
|
|
25
|
+
roles: ['Client', 'Client2', 'Client3', 'Admin'],
|
|
26
|
+
session: {
|
|
27
|
+
jwtSecret: 'dev',
|
|
28
|
+
cookieSession: true,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
security: {
|
|
32
|
+
disableCSRFProtection: true,
|
|
33
|
+
},
|
|
34
|
+
port,
|
|
35
|
+
schema: {
|
|
36
|
+
classes: [
|
|
37
|
+
...additionalClasses,
|
|
38
|
+
{
|
|
39
|
+
name: 'Test',
|
|
40
|
+
fields: {
|
|
41
|
+
field1: { type: 'String' },
|
|
42
|
+
int: { type: 'Int' },
|
|
43
|
+
float: { type: 'Float' },
|
|
44
|
+
array: { type: 'Array', typeValue: 'String' },
|
|
45
|
+
date: { type: 'Date' },
|
|
46
|
+
enum: { type: 'AuthenticationProvider' },
|
|
47
|
+
object: {
|
|
48
|
+
type: 'Object',
|
|
49
|
+
object: {
|
|
50
|
+
name: 'Object',
|
|
51
|
+
fields: {
|
|
52
|
+
array: {
|
|
53
|
+
type: 'Array',
|
|
54
|
+
typeValue: 'Object',
|
|
55
|
+
object: {
|
|
56
|
+
name: 'SubObject',
|
|
57
|
+
fields: {
|
|
58
|
+
string: {
|
|
59
|
+
type: 'String',
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: 'User',
|
|
71
|
+
fields: {
|
|
72
|
+
name: { type: 'String' },
|
|
73
|
+
age: { type: 'Int' },
|
|
74
|
+
isAdmin: { type: 'Boolean', defaultValue: false },
|
|
75
|
+
floatValue: { type: 'Float' },
|
|
76
|
+
birthDate: { type: 'Date' },
|
|
77
|
+
arrayValue: {
|
|
78
|
+
type: 'Array',
|
|
79
|
+
typeValue: 'String',
|
|
80
|
+
},
|
|
81
|
+
test: { type: 'TestScalar' },
|
|
82
|
+
},
|
|
83
|
+
searchableFields: ['email'],
|
|
84
|
+
permissions: {
|
|
85
|
+
create: {
|
|
86
|
+
requireAuthentication: false,
|
|
87
|
+
},
|
|
88
|
+
delete: {
|
|
89
|
+
requireAuthentication: true,
|
|
90
|
+
},
|
|
91
|
+
update: {
|
|
92
|
+
requireAuthentication: false,
|
|
93
|
+
},
|
|
94
|
+
read: {
|
|
95
|
+
requireAuthentication: false,
|
|
96
|
+
},
|
|
97
|
+
acl: async (hookObject) => {
|
|
98
|
+
await hookObject.addACL('users', {
|
|
99
|
+
userId: hookObject.object?.id,
|
|
100
|
+
read: true,
|
|
101
|
+
write: true,
|
|
102
|
+
})
|
|
101
103
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
104
|
+
await hookObject.addACL('roles', null)
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
scalars: [
|
|
110
|
+
{
|
|
111
|
+
name: 'TestScalar',
|
|
112
|
+
description: 'Test scalar',
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
})
|
|
115
117
|
|
|
116
|
-
|
|
118
|
+
await wabe.start()
|
|
117
119
|
|
|
118
|
-
|
|
120
|
+
return { wabe, port }
|
|
119
121
|
}
|
|
120
122
|
|
|
121
123
|
export const closeTests = async (wabe: Wabe<any>) => {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
await wabe.controllers?.database?.adapter?.close()
|
|
125
|
+
await wabe.close()
|
|
124
126
|
}
|
package/bunfig.toml
DELETED
package/dist/index.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { Pool } from "pg";
|
|
2
|
-
import { type AdapterOptions, type DatabaseAdapter, type GetObjectOptions, type CreateObjectOptions, type UpdateObjectOptions, type GetObjectsOptions, type CreateObjectsOptions, type UpdateObjectsOptions, type DeleteObjectsOptions, type WhereType, type DeleteObjectOptions, type OutputType, type CountOptions, type OrderType, type WabeTypes, type SchemaInterface } from "wabe";
|
|
3
|
-
export declare const buildPostgresOrderQuery: <
|
|
4
|
-
T extends WabeTypes,
|
|
5
|
-
K extends keyof T["types"],
|
|
6
|
-
U extends keyof T["types"][K]
|
|
7
|
-
>(order?: OrderType<T, K, U>) => string;
|
|
8
|
-
export declare const buildPostgresWhereQueryAndValues: <
|
|
9
|
-
T extends WabeTypes,
|
|
10
|
-
K extends keyof T["types"]
|
|
11
|
-
>(where?: WhereType<T, K>, startParamIndex?: number, parentKey?: string) => {
|
|
12
|
-
query: string;
|
|
13
|
-
values: any[];
|
|
14
|
-
paramIndex: number;
|
|
15
|
-
};
|
|
16
|
-
export declare class PostgresAdapter<T extends WabeTypes> implements DatabaseAdapter<T> {
|
|
17
|
-
options: AdapterOptions;
|
|
18
|
-
postgresPool: Pool;
|
|
19
|
-
pool: Pool;
|
|
20
|
-
constructor(options: AdapterOptions);
|
|
21
|
-
initializeDatabase(schema: SchemaInterface<T>);
|
|
22
|
-
clearDatabase();
|
|
23
|
-
close();
|
|
24
|
-
createClassIfNotExist(className: keyof T["types"], schema: SchemaInterface<T>);
|
|
25
|
-
count<K extends keyof T["types"]>(params: CountOptions<T, K>);
|
|
26
|
-
getObject<
|
|
27
|
-
K extends keyof T["types"],
|
|
28
|
-
U extends keyof T["types"][K]
|
|
29
|
-
>(params: GetObjectOptions<T, K, U>): Promise<OutputType<T, K, U>>;
|
|
30
|
-
getObjects<
|
|
31
|
-
K extends keyof T["types"],
|
|
32
|
-
U extends keyof T["types"][K],
|
|
33
|
-
W extends keyof T["types"][K]
|
|
34
|
-
>(params: GetObjectsOptions<T, K, U, W>): Promise<OutputType<T, K, W>[]>;
|
|
35
|
-
createObject<
|
|
36
|
-
K extends keyof T["types"],
|
|
37
|
-
U extends keyof T["types"][K],
|
|
38
|
-
W extends keyof T["types"][K]
|
|
39
|
-
>(params: CreateObjectOptions<T, K, U, W>): Promise<{
|
|
40
|
-
id: string;
|
|
41
|
-
}>;
|
|
42
|
-
createObjects<
|
|
43
|
-
K extends keyof T["types"],
|
|
44
|
-
U extends keyof T["types"][K],
|
|
45
|
-
W extends keyof T["types"][K],
|
|
46
|
-
X extends keyof T["types"][K]
|
|
47
|
-
>(params: CreateObjectsOptions<T, K, U, W, X>): Promise<Array<{
|
|
48
|
-
id: string;
|
|
49
|
-
}>>;
|
|
50
|
-
updateObject<
|
|
51
|
-
K extends keyof T["types"],
|
|
52
|
-
U extends keyof T["types"][K],
|
|
53
|
-
W extends keyof T["types"][K]
|
|
54
|
-
>(params: UpdateObjectOptions<T, K, U, W>): Promise<{
|
|
55
|
-
id: string;
|
|
56
|
-
}>;
|
|
57
|
-
updateObjects<
|
|
58
|
-
K extends keyof T["types"],
|
|
59
|
-
U extends keyof T["types"][K],
|
|
60
|
-
W extends keyof T["types"][K],
|
|
61
|
-
X extends keyof T["types"][K]
|
|
62
|
-
>(params: UpdateObjectsOptions<T, K, U, W, X>): Promise<Array<{
|
|
63
|
-
id: string;
|
|
64
|
-
}>>;
|
|
65
|
-
deleteObject<
|
|
66
|
-
K extends keyof T["types"],
|
|
67
|
-
U extends keyof T["types"][K]
|
|
68
|
-
>(params: DeleteObjectOptions<T, K, U>): Promise<void>;
|
|
69
|
-
deleteObjects<
|
|
70
|
-
K extends keyof T["types"],
|
|
71
|
-
U extends keyof T["types"][K],
|
|
72
|
-
W extends keyof T["types"][K]
|
|
73
|
-
>(params: DeleteObjectsOptions<T, K, U, W>): Promise<void>;
|
|
74
|
-
}
|