| 1 |
import { Factory, Model, Registry } from "miragejs"; |
| 2 |
import Schema from "miragejs/orm/schema"; |
| 3 |
|
| 4 |
const FooModel = Model.extend({ |
| 5 |
attr: "text", |
| 6 |
}); |
| 7 |
|
| 8 |
const FooFactory = Factory.extend({ |
| 9 |
attr: "text", |
| 10 |
}); |
| 11 |
|
| 12 |
declare const schema: Schema< |
| 13 |
Registry<{ foo: typeof FooModel }, { foo: typeof FooFactory }> |
| 14 |
>; |
| 15 |
|
| 16 |
schema.create("foo").attr; // $ExpectType string |
| 17 |
schema.create("foo", { attr: "ok" }).attr; // $ExpectType string |
| 18 |
schema.create("foo", { attr: 123 }); // $ExpectError |
| 19 |
schema.create("foo", { x: true }); // $ExpectError |
| 20 |
schema.create("cow"); // $ExpectError |
| 21 |
|
| 22 |
schema.find("foo", "123")?.attr; // $ExpectType string | undefined |
| 23 |
schema.find("foo", ["123"]).models[0].attr; // $ExpectType string |
| 24 |
schema.find("cow", "123"); // $ExpectError |
| 25 |
|
| 26 |
schema.findOrCreateBy("foo", { attr: "hi" }).attr; // $ExpectType string |
| 27 |
schema.findOrCreateBy("foo", { bar: true }); // $ExpectError |
| 28 |
schema.findOrCreateBy("cow", { attr: "bar" }); // $ExpectError |
| 29 |
|
| 30 |
schema.where("foo", { attr: "bar" }).models[0].attr; // $ExpectType string |
| 31 |
schema.where("foo", { bar: true }); // $ExpectError |
| 32 |
schema.where("foo", (foo) => foo.attr === "ok").models[0].attr; // $ExpectType string |
| 33 |
schema.where("foo", (foo) => foo.x === "ok"); // $ExpectError |
| 34 |
schema.where("cow", { attr: "bar" }); // $ExpectError |
| 35 |
|
| 36 |
schema.all("foo").models[0].attr; // $ExpectType string |
| 37 |
schema.all("cow"); // $ExpectError |
| 38 |
|
| 39 |
schema.none("foo").models[0].attr; // $ExpectType string |
| 40 |
schema.none("cow"); // $ExpectError |
| 41 |
|
| 42 |
schema.first("foo")?.attr; // $ExpectType string | undefined |
| 43 |
schema.first("cow"); // $ExpectError |