Skip to content

Commit

Permalink
Ensure correct behavior for model definition (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
leo authored Feb 13, 2025
1 parent 32bdc12 commit 90dd10d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ export const getSyntaxProxy = <Structure, ReturnValue = ResultRecord>(config?: {
replacer?: (value: unknown) => unknown | undefined;
propertyValue?: unknown;
modelType?: boolean;
chaining?: boolean;
}): DeepCallable<Structure, ReturnValue> => {
// The default value of a property within the composed structure.
const propertyValue =
typeof config?.propertyValue === 'undefined' ? {} : config.propertyValue;

const shouldAllowChaining = config?.chaining ?? true;

const createProxy = (
path: Array<string> = [],
targetProps?: object,
Expand Down Expand Up @@ -115,7 +118,7 @@ export const getSyntaxProxy = <Structure, ReturnValue = ResultRecord>(config?: {
// holds an `undefined` value.
if (options) details.options = options;

return createProxy(newPath, details, true);
return shouldAllowChaining ? createProxy(newPath, details, true) : details;
}

return config.callback(structure, options);
Expand Down
2 changes: 1 addition & 1 deletion src/schema/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ type Expand<T> = T extends infer O ? { [K in keyof O]: O[K] } : never;
export const model = <Fields extends RecordWithoutForbiddenKeys<Primitives>>(
model: Model<Fields> | (() => Model<Fields>),
): Expand<RoninFields & FieldsToTypes<Fields>> => {
return getSyntaxProxy({ modelType: true })(model) as unknown as Expand<
return getSyntaxProxy({ modelType: true, chaining: false })(model) as unknown as Expand<
RoninFields & FieldsToTypes<Fields>
>;
};

0 comments on commit 90dd10d

Please sign in to comment.