New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cwqt/refract

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cwqt/refract - npm Package Compare versions

Comparing version 1.3.1 to 1.3.2

6

dist/codegen/validate.js

@@ -54,5 +54,5 @@ Object.defineProperty(exports, "__esModule", { value: true });

throw new Error(`RelationshipErr: You must specify the same number of fields in 'fields' and 'references' for relation '${relation.name}' in model '${model.name}'`);
for (let index = 0; index < fields.value.length; index++) {
const field = fields.value[index];
const reference = references.value[index];
for (let i = 0; i < fields.value.length; i++) {
const field = fields.value[i];
const reference = references.value[i];
const column = model.columns.find(c => c.name === field);

@@ -59,0 +59,0 @@ const otherSideColumn = otherSideModel.columns.find(c => c.name === reference);

@@ -7,6 +7,9 @@ import * as Types from '../../types';

export declare const OneToOne: <T extends "OneToOne", M extends Types.Blocks.Model, K extends "name" | "comment" | "model" | "nullable" | "fields" | "references" | "onUpdate" | "onDelete">(model: M, ...modifiers: OptionallyWithName<"OneToOne", [fields: Types.Modifier<"OneToOne", "fields">, references: Types.Modifier<"OneToOne", "references">, ...modifiers: Types.Modifier<"OneToOne", Exclude<K, "name" | "fields" | "references">>[]]> | OptionallyWithName<T, Types.Modifier<T, Exclude<K, "fields" | "references">>[]>) => Types.Fields.Field<T, K>;
export declare const Fields: <T extends "OneToOne" | "ManyToOne">(...fields: string[]) => Types.Modifier<T, "fields">;
export declare const References: <T extends "OneToOne" | "ManyToOne">(...references: string[]) => Types.Modifier<T, "references">;
export declare const Fields: <T extends "OneToOne" | "ManyToOne">(...fields: string[] | [
reference: string,
scalar: Types.Fields.Field<'Int'> | Types.Fields.Field<'String'>
]) => Types.Modifier<T, "fields">;
export declare const References: <T extends "OneToOne" | "ManyToOne">(...reference: string[]) => Types.Modifier<T, "references">;
export declare const OnUpdate: <T extends "OneToOne" | "ManyToOne">(referentialAction: ReferentialAction) => Types.Modifier<T, "onUpdate">;
export declare const OnDelete: <T extends "OneToOne" | "ManyToOne">(referentialAction: ReferentialAction) => Types.Modifier<T, "onDelete">;
export {};

@@ -45,5 +45,5 @@ Object.defineProperty(exports, "__esModule", { value: true });

exports.Fields = Fields;
const References = (...references) => ({
const References = (...reference) => ({
type: 'references',
value: references,
value: reference,
});

@@ -50,0 +50,0 @@ exports.References = References;

Object.defineProperty(exports, "__esModule", { value: true });
exports.$Model = exports.Model = void 0;
const fields_1 = require("../types/fields");
const Model = (name, comment) => new $Model(name, comment);

@@ -36,2 +37,7 @@ exports.Model = Model;

type.modifiers.push({ type: 'comment', value: comment });
const fields = type.modifiers.find(m => m.type == 'fields');
if ((0, fields_1.isScalar)(fields?.value?.[1])) {
this.Field(fields.value[0], fields.value[1]);
fields.value.pop();
}
this.columns.push({ name, ...type });

@@ -38,0 +44,0 @@ return this;

@@ -36,9 +36,10 @@ Object.defineProperty(exports, "__esModule", { value: true });

function isScalar(column) {
return [
isRelation(column),
isEnumKey(column),
isEnum(column),
isCompound(column),
].every(v => v == false);
return (typeof column == 'object' &&
[
isRelation(column),
isEnumKey(column),
isEnum(column),
isCompound(column),
].every(v => v == false));
}
exports.isScalar = isScalar;

@@ -0,1 +1,2 @@

import { Types } from '..';
import { JsonValue } from '../codegen/lib/json';

@@ -69,7 +70,11 @@ import { Model } from './blocks';

};
export declare type Reference = [
reference: string,
scalar?: Types.Fields.Field<'Int'> | Types.Fields.Field<'String'>
];
export declare type Relations = Append<{
OneToMany: {};
OneToOne: {
fields?: string[];
references?: string[];
fields?: string[] | Reference;
references?: Reference | string[];
onUpdate?: ReferentialAction;

@@ -80,3 +85,3 @@ onDelete?: ReferentialAction;

ManyToOne: {
fields: string[];
fields: string[] | Reference;
references: string[];

@@ -83,0 +88,0 @@ onUpdate?: ReferentialAction;

{
"name": "@cwqt/refract",
"version": "1.3.1",
"version": "1.3.2",
"description": "Generate Prisma from TypeScript",

@@ -5,0 +5,0 @@ "author": "cwqt",

@@ -179,6 +179,9 @@ # refract

Something.Field('id', PrimaryKey)
Something
.Field('id', PrimaryKey)
// Holds foreign key
.Field('userId', Int())
.Relation('user', OneToOne(User, Fields('userId'), References('id')));
// Alternatively you can do Fields('userId', Int()) to avoid the extra
// .Field() call, this'll add the column to the model for you

@@ -185,0 +188,0 @@ User

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc