@zenstackhq/server 3.5.0-beta.2 → 3.5.0-beta.4

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/api.d.cts CHANGED
@@ -1,6 +1,37 @@
1
+ import { QueryOptions } from '@zenstackhq/orm';
1
2
  import { SchemaDef } from '@zenstackhq/orm/schema';
3
+ import * as openapi_types from 'openapi-types';
4
+ import { OpenAPIV3_1 } from 'openapi-types';
2
5
  import { A as ApiHandler, L as LogConfig, R as RequestContext, a as Response } from './types-CU_PWKr9.cjs';
3
- import '@zenstackhq/orm';
6
+
7
+ type CommonHandlerOptions<Schema extends SchemaDef> = {
8
+ /** Query options that affect the behavior of the OpenAPI provider. */
9
+ queryOptions?: QueryOptions<Schema>;
10
+ };
11
+ type OpenApiSpecOptions = {
12
+ /** Spec title. Defaults to 'ZenStack Generated API' */
13
+ title?: string;
14
+ /** Spec version. Defaults to '1.0.0' */
15
+ version?: string;
16
+ /** Spec description. */
17
+ description?: string;
18
+ /** Spec summary. */
19
+ summary?: string;
20
+ /**
21
+ * When true, assumes that the schema includes access policies, and adds
22
+ * 403 responses to operations that can potentially be rejected.
23
+ */
24
+ respectAccessPolicies?: boolean;
25
+ };
26
+ /**
27
+ * Interface for generating OpenAPI specifications.
28
+ */
29
+ interface OpenApiSpecGenerator {
30
+ /**
31
+ * Generates an OpenAPI v3.1 specification document.
32
+ */
33
+ generateSpec(options?: OpenApiSpecOptions): Promise<OpenAPIV3_1.Document>;
34
+ }
4
35
 
5
36
  /**
6
37
  * Options for {@link RestApiHandler}
@@ -45,11 +76,11 @@ type RestApiHandlerOptions<Schema extends SchemaDef = SchemaDef> = {
45
76
  * Mapping from model names to unique field name to be used as resource's ID.
46
77
  */
47
78
  externalIdMapping?: Record<string, string>;
48
- };
79
+ } & CommonHandlerOptions<Schema>;
49
80
  /**
50
81
  * RESTful-style API request handler (compliant with JSON:API)
51
82
  */
52
- declare class RestApiHandler<Schema extends SchemaDef = SchemaDef> implements ApiHandler<Schema> {
83
+ declare class RestApiHandler<Schema extends SchemaDef = SchemaDef> implements ApiHandler<Schema>, OpenApiSpecGenerator {
53
84
  private readonly options;
54
85
  private serializers;
55
86
  private readonly errors;
@@ -122,6 +153,7 @@ declare class RestApiHandler<Schema extends SchemaDef = SchemaDef> implements Ap
122
153
  private makeError;
123
154
  private makeUnsupportedModelError;
124
155
  private makeUnsupportedRelationshipError;
156
+ generateSpec(options?: OpenApiSpecOptions): Promise<openapi_types.OpenAPIV3_1.Document<{}>>;
125
157
  }
126
158
 
127
159
  /**
@@ -136,7 +168,7 @@ type RPCApiHandlerOptions<Schema extends SchemaDef = SchemaDef> = {
136
168
  * Logging configuration
137
169
  */
138
170
  log?: LogConfig;
139
- };
171
+ } & CommonHandlerOptions<Schema>;
140
172
  /**
141
173
  * RPC style API request handler that mirrors the ZenStackClient API
142
174
  */
@@ -156,4 +188,4 @@ declare class RPCApiHandler<Schema extends SchemaDef = SchemaDef> implements Api
156
188
  private processRequestPayload;
157
189
  }
158
190
 
159
- export { RPCApiHandler, type RPCApiHandlerOptions, RestApiHandler, type RestApiHandlerOptions };
191
+ export { type OpenApiSpecGenerator, type OpenApiSpecOptions, RPCApiHandler, type RPCApiHandlerOptions, RestApiHandler, type RestApiHandlerOptions };
package/dist/api.d.ts CHANGED
@@ -1,6 +1,37 @@
1
+ import { QueryOptions } from '@zenstackhq/orm';
1
2
  import { SchemaDef } from '@zenstackhq/orm/schema';
3
+ import * as openapi_types from 'openapi-types';
4
+ import { OpenAPIV3_1 } from 'openapi-types';
2
5
  import { A as ApiHandler, L as LogConfig, R as RequestContext, a as Response } from './types-CU_PWKr9.js';
3
- import '@zenstackhq/orm';
6
+
7
+ type CommonHandlerOptions<Schema extends SchemaDef> = {
8
+ /** Query options that affect the behavior of the OpenAPI provider. */
9
+ queryOptions?: QueryOptions<Schema>;
10
+ };
11
+ type OpenApiSpecOptions = {
12
+ /** Spec title. Defaults to 'ZenStack Generated API' */
13
+ title?: string;
14
+ /** Spec version. Defaults to '1.0.0' */
15
+ version?: string;
16
+ /** Spec description. */
17
+ description?: string;
18
+ /** Spec summary. */
19
+ summary?: string;
20
+ /**
21
+ * When true, assumes that the schema includes access policies, and adds
22
+ * 403 responses to operations that can potentially be rejected.
23
+ */
24
+ respectAccessPolicies?: boolean;
25
+ };
26
+ /**
27
+ * Interface for generating OpenAPI specifications.
28
+ */
29
+ interface OpenApiSpecGenerator {
30
+ /**
31
+ * Generates an OpenAPI v3.1 specification document.
32
+ */
33
+ generateSpec(options?: OpenApiSpecOptions): Promise<OpenAPIV3_1.Document>;
34
+ }
4
35
 
5
36
  /**
6
37
  * Options for {@link RestApiHandler}
@@ -45,11 +76,11 @@ type RestApiHandlerOptions<Schema extends SchemaDef = SchemaDef> = {
45
76
  * Mapping from model names to unique field name to be used as resource's ID.
46
77
  */
47
78
  externalIdMapping?: Record<string, string>;
48
- };
79
+ } & CommonHandlerOptions<Schema>;
49
80
  /**
50
81
  * RESTful-style API request handler (compliant with JSON:API)
51
82
  */
52
- declare class RestApiHandler<Schema extends SchemaDef = SchemaDef> implements ApiHandler<Schema> {
83
+ declare class RestApiHandler<Schema extends SchemaDef = SchemaDef> implements ApiHandler<Schema>, OpenApiSpecGenerator {
53
84
  private readonly options;
54
85
  private serializers;
55
86
  private readonly errors;
@@ -122,6 +153,7 @@ declare class RestApiHandler<Schema extends SchemaDef = SchemaDef> implements Ap
122
153
  private makeError;
123
154
  private makeUnsupportedModelError;
124
155
  private makeUnsupportedRelationshipError;
156
+ generateSpec(options?: OpenApiSpecOptions): Promise<openapi_types.OpenAPIV3_1.Document<{}>>;
125
157
  }
126
158
 
127
159
  /**
@@ -136,7 +168,7 @@ type RPCApiHandlerOptions<Schema extends SchemaDef = SchemaDef> = {
136
168
  * Logging configuration
137
169
  */
138
170
  log?: LogConfig;
139
- };
171
+ } & CommonHandlerOptions<Schema>;
140
172
  /**
141
173
  * RPC style API request handler that mirrors the ZenStackClient API
142
174
  */
@@ -156,4 +188,4 @@ declare class RPCApiHandler<Schema extends SchemaDef = SchemaDef> implements Api
156
188
  private processRequestPayload;
157
189
  }
158
190
 
159
- export { RPCApiHandler, type RPCApiHandlerOptions, RestApiHandler, type RestApiHandlerOptions };
191
+ export { type OpenApiSpecGenerator, type OpenApiSpecOptions, RPCApiHandler, type RPCApiHandlerOptions, RestApiHandler, type RestApiHandlerOptions };