@zenstackhq/testtools 3.0.0-beta.3 → 3.0.0-beta.30

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/dist/index.d.cts CHANGED
@@ -1,18 +1,89 @@
1
- import { SchemaDef } from '@zenstackhq/sdk/schema';
1
+ import { ClientOptions, ClientContract } from '@zenstackhq/orm';
2
+ import { SchemaDef } from '@zenstackhq/orm/schema';
3
+ import { LogEvent } from 'kysely';
4
+ import * as _zenstackhq_language_ast from '@zenstackhq/language/ast';
5
+ import { SchemaDef as SchemaDef$1 } from '@zenstackhq/schema';
2
6
 
3
- declare function createTestProject(): string;
7
+ declare function getTestDbProvider(): "sqlite" | "postgresql";
8
+ declare const TEST_PG_CONFIG: {
9
+ host: string;
10
+ port: number;
11
+ user: string;
12
+ password: string;
13
+ };
14
+ declare const TEST_PG_URL: string;
15
+ type ExtraTestClientOptions = {
16
+ /**
17
+ * Database provider
18
+ */
19
+ provider?: 'sqlite' | 'postgresql';
20
+ /**
21
+ * The main ZModel file. Only used when `usePrismaPush` is true and `schema` is an object.
22
+ */
23
+ schemaFile?: string;
24
+ /**
25
+ * Database name. If not provided, a name will be generated based on the test name.
26
+ */
27
+ dbName?: string;
28
+ /**
29
+ * Use `prisma db push` instead of ZenStack's `$pushSchema` for database initialization.
30
+ */
31
+ usePrismaPush?: boolean;
32
+ /**
33
+ * Extra source files to create and compile.
34
+ */
35
+ extraSourceFiles?: Record<string, string>;
36
+ /**
37
+ * Working directory for the test client. If not provided, a temporary directory will be created.
38
+ */
39
+ workDir?: string;
40
+ /**
41
+ * Debug mode.
42
+ */
43
+ debug?: boolean;
44
+ /**
45
+ * A sqlite database file to be used for the test. Only supported for sqlite provider.
46
+ */
47
+ dbFile?: string;
48
+ /**
49
+ * PostgreSQL extensions to be added to the datasource. Only supported for postgresql provider.
50
+ */
51
+ dataSourceExtensions?: string[];
52
+ /**
53
+ * Additional files to be copied to the working directory. The glob pattern is relative to the test file.
54
+ */
55
+ copyFiles?: {
56
+ globPattern: string;
57
+ destination: string;
58
+ }[];
59
+ };
60
+ type CreateTestClientOptions<Schema extends SchemaDef> = Omit<ClientOptions<Schema>, 'dialect'> & ExtraTestClientOptions;
61
+ declare function createTestClient<Schema extends SchemaDef, Options extends ClientOptions<Schema>, CreateOptions = Omit<Options, 'dialect'>>(schema: Schema, options?: CreateOptions): Promise<ClientContract<Schema, Options>>;
62
+ declare function createTestClient(schema: string, options?: CreateTestClientOptions<SchemaDef>): Promise<any>;
63
+ declare function createPolicyTestClient<Schema extends SchemaDef>(schema: Schema, options?: CreateTestClientOptions<Schema>): Promise<ClientContract<Schema>>;
64
+ declare function createPolicyTestClient<Schema extends SchemaDef>(schema: string, options?: CreateTestClientOptions<Schema>): Promise<any>;
65
+ declare function testLogger(e: LogEvent): void;
4
66
 
5
- declare function generateTsSchema(schemaText: string, provider?: 'sqlite' | 'postgresql', dbUrl?: string, extraSourceFiles?: Record<string, string>): Promise<{
67
+ declare function createTestProject(zmodelContent?: string): string;
68
+
69
+ declare function generateTsSchema(schemaText: string, provider?: 'sqlite' | 'postgresql', dbUrl?: string, extraSourceFiles?: Record<string, string>, withLiteSchema?: boolean): Promise<{
70
+ model: _zenstackhq_language_ast.Model;
6
71
  workDir: string;
7
- schema: SchemaDef;
72
+ schema: SchemaDef$1;
73
+ schemaLite: SchemaDef$1 | undefined;
8
74
  }>;
9
75
  declare function generateTsSchemaFromFile(filePath: string): Promise<{
76
+ model: _zenstackhq_language_ast.Model;
10
77
  workDir: string;
11
- schema: SchemaDef;
78
+ schema: SchemaDef$1;
79
+ schemaLite: SchemaDef$1 | undefined;
12
80
  }>;
13
81
  declare function generateTsSchemaInPlace(schemaPath: string): Promise<{
14
82
  workDir: string;
15
- schema: SchemaDef;
83
+ schema: SchemaDef$1;
84
+ schemaLite: SchemaDef$1 | undefined;
16
85
  }>;
86
+ declare function loadSchema(schema: string, additionalSchemas?: Record<string, string>): Promise<_zenstackhq_language_ast.Model>;
87
+ declare function loadSchemaWithError(schema: string, error: string | RegExp): Promise<void>;
17
88
 
18
- export { createTestProject, generateTsSchema, generateTsSchemaFromFile, generateTsSchemaInPlace };
89
+ export { type CreateTestClientOptions, TEST_PG_CONFIG, TEST_PG_URL, createPolicyTestClient, createTestClient, createTestProject, generateTsSchema, generateTsSchemaFromFile, generateTsSchemaInPlace, getTestDbProvider, loadSchema, loadSchemaWithError, testLogger };
package/dist/index.d.ts CHANGED
@@ -1,18 +1,89 @@
1
- import { SchemaDef } from '@zenstackhq/sdk/schema';
1
+ import { ClientOptions, ClientContract } from '@zenstackhq/orm';
2
+ import { SchemaDef } from '@zenstackhq/orm/schema';
3
+ import { LogEvent } from 'kysely';
4
+ import * as _zenstackhq_language_ast from '@zenstackhq/language/ast';
5
+ import { SchemaDef as SchemaDef$1 } from '@zenstackhq/schema';
2
6
 
3
- declare function createTestProject(): string;
7
+ declare function getTestDbProvider(): "sqlite" | "postgresql";
8
+ declare const TEST_PG_CONFIG: {
9
+ host: string;
10
+ port: number;
11
+ user: string;
12
+ password: string;
13
+ };
14
+ declare const TEST_PG_URL: string;
15
+ type ExtraTestClientOptions = {
16
+ /**
17
+ * Database provider
18
+ */
19
+ provider?: 'sqlite' | 'postgresql';
20
+ /**
21
+ * The main ZModel file. Only used when `usePrismaPush` is true and `schema` is an object.
22
+ */
23
+ schemaFile?: string;
24
+ /**
25
+ * Database name. If not provided, a name will be generated based on the test name.
26
+ */
27
+ dbName?: string;
28
+ /**
29
+ * Use `prisma db push` instead of ZenStack's `$pushSchema` for database initialization.
30
+ */
31
+ usePrismaPush?: boolean;
32
+ /**
33
+ * Extra source files to create and compile.
34
+ */
35
+ extraSourceFiles?: Record<string, string>;
36
+ /**
37
+ * Working directory for the test client. If not provided, a temporary directory will be created.
38
+ */
39
+ workDir?: string;
40
+ /**
41
+ * Debug mode.
42
+ */
43
+ debug?: boolean;
44
+ /**
45
+ * A sqlite database file to be used for the test. Only supported for sqlite provider.
46
+ */
47
+ dbFile?: string;
48
+ /**
49
+ * PostgreSQL extensions to be added to the datasource. Only supported for postgresql provider.
50
+ */
51
+ dataSourceExtensions?: string[];
52
+ /**
53
+ * Additional files to be copied to the working directory. The glob pattern is relative to the test file.
54
+ */
55
+ copyFiles?: {
56
+ globPattern: string;
57
+ destination: string;
58
+ }[];
59
+ };
60
+ type CreateTestClientOptions<Schema extends SchemaDef> = Omit<ClientOptions<Schema>, 'dialect'> & ExtraTestClientOptions;
61
+ declare function createTestClient<Schema extends SchemaDef, Options extends ClientOptions<Schema>, CreateOptions = Omit<Options, 'dialect'>>(schema: Schema, options?: CreateOptions): Promise<ClientContract<Schema, Options>>;
62
+ declare function createTestClient(schema: string, options?: CreateTestClientOptions<SchemaDef>): Promise<any>;
63
+ declare function createPolicyTestClient<Schema extends SchemaDef>(schema: Schema, options?: CreateTestClientOptions<Schema>): Promise<ClientContract<Schema>>;
64
+ declare function createPolicyTestClient<Schema extends SchemaDef>(schema: string, options?: CreateTestClientOptions<Schema>): Promise<any>;
65
+ declare function testLogger(e: LogEvent): void;
4
66
 
5
- declare function generateTsSchema(schemaText: string, provider?: 'sqlite' | 'postgresql', dbUrl?: string, extraSourceFiles?: Record<string, string>): Promise<{
67
+ declare function createTestProject(zmodelContent?: string): string;
68
+
69
+ declare function generateTsSchema(schemaText: string, provider?: 'sqlite' | 'postgresql', dbUrl?: string, extraSourceFiles?: Record<string, string>, withLiteSchema?: boolean): Promise<{
70
+ model: _zenstackhq_language_ast.Model;
6
71
  workDir: string;
7
- schema: SchemaDef;
72
+ schema: SchemaDef$1;
73
+ schemaLite: SchemaDef$1 | undefined;
8
74
  }>;
9
75
  declare function generateTsSchemaFromFile(filePath: string): Promise<{
76
+ model: _zenstackhq_language_ast.Model;
10
77
  workDir: string;
11
- schema: SchemaDef;
78
+ schema: SchemaDef$1;
79
+ schemaLite: SchemaDef$1 | undefined;
12
80
  }>;
13
81
  declare function generateTsSchemaInPlace(schemaPath: string): Promise<{
14
82
  workDir: string;
15
- schema: SchemaDef;
83
+ schema: SchemaDef$1;
84
+ schemaLite: SchemaDef$1 | undefined;
16
85
  }>;
86
+ declare function loadSchema(schema: string, additionalSchemas?: Record<string, string>): Promise<_zenstackhq_language_ast.Model>;
87
+ declare function loadSchemaWithError(schema: string, error: string | RegExp): Promise<void>;
17
88
 
18
- export { createTestProject, generateTsSchema, generateTsSchemaFromFile, generateTsSchemaInPlace };
89
+ export { type CreateTestClientOptions, TEST_PG_CONFIG, TEST_PG_URL, createPolicyTestClient, createTestClient, createTestProject, generateTsSchema, generateTsSchemaFromFile, generateTsSchemaInPlace, getTestDbProvider, loadSchema, loadSchemaWithError, testLogger };