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

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
@@ -76,6 +76,14 @@ type RestApiHandlerOptions<Schema extends SchemaDef = SchemaDef> = {
76
76
  * Mapping from model names to unique field name to be used as resource's ID.
77
77
  */
78
78
  externalIdMapping?: Record<string, string>;
79
+ /**
80
+ * When `true`, enables nested route handling for all to-many relations:
81
+ * `/:parentType/:parentId/:relationName` (collection) and
82
+ * `/:parentType/:parentId/:relationName/:childId` (single).
83
+ *
84
+ * Defaults to `false`.
85
+ */
86
+ nestedRoutes?: boolean;
79
87
  } & CommonHandlerOptions<Schema>;
80
88
  /**
81
89
  * RESTful-style API request handler (compliant with JSON:API)
@@ -95,22 +103,60 @@ declare class RestApiHandler<Schema extends SchemaDef = SchemaDef> implements Ap
95
103
  private modelNameMapping;
96
104
  private reverseModelNameMapping;
97
105
  private externalIdMapping;
106
+ private nestedRoutes;
98
107
  constructor(options: RestApiHandlerOptions<Schema>);
99
108
  private validateOptions;
100
109
  get schema(): Schema;
101
110
  get log(): LogConfig | undefined;
102
111
  private buildUrlPatternMap;
103
112
  private mapModelName;
113
+ /**
114
+ * Resolves child model type and reverse relation from a parent relation name.
115
+ * e.g. given parentType='user', parentRelation='posts', returns { childType:'post', reverseRelation:'author' }
116
+ */
117
+ private resolveNestedRelation;
118
+ private mergeFilters;
119
+ /**
120
+ * Builds a WHERE filter for the child model that constrains results to those belonging to the given parent.
121
+ * @param parentType lowercased parent model name
122
+ * @param parentId parent resource ID string
123
+ * @param parentRelation relation field name on the parent model (e.g. 'posts')
124
+ */
125
+ private buildNestedParentFilter;
104
126
  private matchUrlPattern;
105
127
  handleRequest({ client, method, path, query, requestBody }: RequestContext<Schema>): Promise<Response>;
106
128
  private handleGenericError;
107
129
  private processProcedureRequest;
108
130
  private makeProcBadInputErrorResponse;
109
131
  private makeProcGenericErrorResponse;
132
+ /**
133
+ * Builds the ORM `args` object (include, select) shared by single-read operations.
134
+ * Returns the args to pass to findUnique/findFirst and the resolved `include` list for serialization,
135
+ * or an error response if query params are invalid.
136
+ */
137
+ private buildSingleReadArgs;
110
138
  private processSingleRead;
111
139
  private processFetchRelated;
112
140
  private processReadRelationship;
113
141
  private processCollectionRead;
142
+ /**
143
+ * Builds link URL for a nested resource using parent type, parent ID, relation name, and optional child ID.
144
+ * Uses the parent model name mapping for the parent segment; the relation name is used as-is.
145
+ */
146
+ private makeNestedLinkUrl;
147
+ private processNestedSingleRead;
148
+ private processNestedCreate;
149
+ /**
150
+ * Builds the ORM `data` payload for a nested update, shared by both to-many (childId present)
151
+ * and to-one (childId absent) variants. Returns either `{ updateData }` or `{ error }`.
152
+ */
153
+ private buildNestedUpdatePayload;
154
+ /**
155
+ * Handles PATCH /:type/:id/:relationship/:childId (to-many) and
156
+ * PATCH /:type/:id/:relationship (to-one, childId undefined).
157
+ */
158
+ private processNestedUpdate;
159
+ private processNestedDelete;
114
160
  private buildPartialSelect;
115
161
  private addTotalCountToMeta;
116
162
  private makePaginator;
package/dist/api.d.ts CHANGED
@@ -76,6 +76,14 @@ type RestApiHandlerOptions<Schema extends SchemaDef = SchemaDef> = {
76
76
  * Mapping from model names to unique field name to be used as resource's ID.
77
77
  */
78
78
  externalIdMapping?: Record<string, string>;
79
+ /**
80
+ * When `true`, enables nested route handling for all to-many relations:
81
+ * `/:parentType/:parentId/:relationName` (collection) and
82
+ * `/:parentType/:parentId/:relationName/:childId` (single).
83
+ *
84
+ * Defaults to `false`.
85
+ */
86
+ nestedRoutes?: boolean;
79
87
  } & CommonHandlerOptions<Schema>;
80
88
  /**
81
89
  * RESTful-style API request handler (compliant with JSON:API)
@@ -95,22 +103,60 @@ declare class RestApiHandler<Schema extends SchemaDef = SchemaDef> implements Ap
95
103
  private modelNameMapping;
96
104
  private reverseModelNameMapping;
97
105
  private externalIdMapping;
106
+ private nestedRoutes;
98
107
  constructor(options: RestApiHandlerOptions<Schema>);
99
108
  private validateOptions;
100
109
  get schema(): Schema;
101
110
  get log(): LogConfig | undefined;
102
111
  private buildUrlPatternMap;
103
112
  private mapModelName;
113
+ /**
114
+ * Resolves child model type and reverse relation from a parent relation name.
115
+ * e.g. given parentType='user', parentRelation='posts', returns { childType:'post', reverseRelation:'author' }
116
+ */
117
+ private resolveNestedRelation;
118
+ private mergeFilters;
119
+ /**
120
+ * Builds a WHERE filter for the child model that constrains results to those belonging to the given parent.
121
+ * @param parentType lowercased parent model name
122
+ * @param parentId parent resource ID string
123
+ * @param parentRelation relation field name on the parent model (e.g. 'posts')
124
+ */
125
+ private buildNestedParentFilter;
104
126
  private matchUrlPattern;
105
127
  handleRequest({ client, method, path, query, requestBody }: RequestContext<Schema>): Promise<Response>;
106
128
  private handleGenericError;
107
129
  private processProcedureRequest;
108
130
  private makeProcBadInputErrorResponse;
109
131
  private makeProcGenericErrorResponse;
132
+ /**
133
+ * Builds the ORM `args` object (include, select) shared by single-read operations.
134
+ * Returns the args to pass to findUnique/findFirst and the resolved `include` list for serialization,
135
+ * or an error response if query params are invalid.
136
+ */
137
+ private buildSingleReadArgs;
110
138
  private processSingleRead;
111
139
  private processFetchRelated;
112
140
  private processReadRelationship;
113
141
  private processCollectionRead;
142
+ /**
143
+ * Builds link URL for a nested resource using parent type, parent ID, relation name, and optional child ID.
144
+ * Uses the parent model name mapping for the parent segment; the relation name is used as-is.
145
+ */
146
+ private makeNestedLinkUrl;
147
+ private processNestedSingleRead;
148
+ private processNestedCreate;
149
+ /**
150
+ * Builds the ORM `data` payload for a nested update, shared by both to-many (childId present)
151
+ * and to-one (childId absent) variants. Returns either `{ updateData }` or `{ error }`.
152
+ */
153
+ private buildNestedUpdatePayload;
154
+ /**
155
+ * Handles PATCH /:type/:id/:relationship/:childId (to-many) and
156
+ * PATCH /:type/:id/:relationship (to-one, childId undefined).
157
+ */
158
+ private processNestedUpdate;
159
+ private processNestedDelete;
114
160
  private buildPartialSelect;
115
161
  private addTotalCountToMeta;
116
162
  private makePaginator;