
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
accel-record-factory
Advanced tools
Language: [English](https://github.com/koyopro/accella/blob/main/packages/accel-record-factory/README.md) | [日本語](https://github.com/koyopro/accella/blob/main/packages/accel-record-factory/README-ja.md)
This is a factory library for Accel Record.
npm install -D accel-record-factory
Add the configuration for prisma-generator-accel-record
to prisma/schema.prisma
.
generator client {
provider = "prisma-client-js"
output = "../src/prisma/client"
}
generator accelRecord {
provider = "prisma-generator-accel-record"
output = "../src/models"
factoryPath = "../tests/factories" // Add the output destination for factory files
}
After modifying prisma/schema.prisma
, run the following command:
npx prisma generate
For example, if you define a User model like this:
// prisma/schema.prisma
model User {
id Int @id @default(autoincrement())
firstName String
lastName String
age Int?
}
The following factory file will be automatically generated:
// tests/factories/user.ts
import { defineFactory } from "accel-record-factory";
import { User } from "../../src/models/index.js";
export const UserFactory = defineFactory(User, {
// firstName: "MyString",
// lastName: "MyString",
// age: 1,
});
export { UserFactory as $User };
You can import and use the factory:
// tests/user.test.ts
import { $User } from "./factories/user";
const newUser = $User.build();
const user = $User.create({
firstName: "John",
lastName: "Doe",
age: 20,
});
You can set default values by passing them as the second argument to defineFactory.
// tests/factories/user.ts
import { defineFactory } from "accel-record-factory";
import { User } from "../../src/models/index.js";
export const UserFactory = defineFactory(User, {
firstName: "John", // Set default value
lastName: "Doe",
age: 20,
});
export { UserFactory as $User };
// tests/user.test.ts
import { $User } from "./factories/user";
const newUser = $User.build();
newUser.firstName; // => "John"
newUser.lastName; // => "Doe"
newUser.age; // => 20
When setting default values with defineFactory, you can use a function to utilize sequential numbers.
// tests/factories/user.ts
import { defineFactory } from "accel-record-factory";
import { User } from "../../src/models/index.js";
export const UserFactory = defineFactory(User, {
firstName: (seq) => `User${seq}`, // Specify a function to use sequential numbers
});
export { UserFactory as $User };
// tests/user.test.ts
import { $User } from "./factories/user";
const user1 = $User.build();
user1.firstName; // => "User1"
const user2 = $User.build();
user2.firstName; // => "User2"
By specifying a function for the default value, you can generate models with associations.
// prisma/schema.prisma
model User {
id Int @id @default(autoincrement())
firstName String
lastName String
age Int?
setting Setting? // Associated model
}
model Setting {
id Int @id @default(autoincrement())
userId Int
user User @relation(fields: [userId], references: [id])
notify Boolean
}
// tests/factories/user.ts
import { defineFactory } from "accel-record-factory";
import { User, Setting } from "../../src/models/index.js";
export const UserFactory = defineFactory(User, {
setting: () => Setting.build({ notify: true }), // Specify a function to generate the association
});
export { UserFactory as $User };
// tests/user.test.ts
import { $User } from "./factories/user";
const user = $User.build();
user.setting.notify; // => true
By specifying traits as the third argument to defineFactory, you can set multiple default values.
// tests/factories/user.ts
import { defineFactory } from "accel-record-factory";
import { User } from "../../src/models/index.js";
export const UserFactory = defineFactory(
User,
{
firstName: "John",
lastName: "Doe",
},
{
traits: {
// Specify the trait name
foo: {
firstName: "Foo",
lastName: "Bar",
},
},
}
);
export { UserFactory as $User };
// tests/user.test.ts
import { $User } from "./factories/user";
const john = $User.build({});
john.firstName; // => "John"
john.lastName; // => "Doe"
const foo = $User.build({}, "foo"); // Use the trait
foo.firstName; // => "Foo"
foo.lastName; // => "Bar"
FAQs
Language: [English](https://github.com/koyopro/accella/blob/main/packages/accel-record-factory/README.md) | [日本語](https://github.com/koyopro/accella/blob/main/packages/accel-record-factory/README-ja.md)
The npm package accel-record-factory receives a total of 16 weekly downloads. As such, accel-record-factory popularity was classified as not popular.
We found that accel-record-factory demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.