joist-orm 2.3.0-next.2 → 2.3.0-next.4

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.
@@ -1,2 +1,3 @@
1
1
  export { PostgresDriver, PostgresDriverOpts, setupLatestPgTypes } from "./drivers/PostgresDriver.js";
2
+ export { seed } from "./seed.js";
2
3
  //# sourceMappingURL=pg-export.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pg-export.d.ts","sourceRoot":"","sources":["../src/pg-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC"}
1
+ {"version":3,"file":"pg-export.d.ts","sourceRoot":"","sources":["../src/pg-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACrG,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setupLatestPgTypes = exports.PostgresDriver = void 0;
3
+ exports.seed = exports.setupLatestPgTypes = exports.PostgresDriver = void 0;
4
4
  var PostgresDriver_js_1 = require("./drivers/PostgresDriver.js");
5
5
  Object.defineProperty(exports, "PostgresDriver", { enumerable: true, get: function () { return PostgresDriver_js_1.PostgresDriver; } });
6
6
  Object.defineProperty(exports, "setupLatestPgTypes", { enumerable: true, get: function () { return PostgresDriver_js_1.setupLatestPgTypes; } });
7
+ var seed_js_1 = require("./seed.js");
8
+ Object.defineProperty(exports, "seed", { enumerable: true, get: function () { return seed_js_1.seed; } });
7
9
  //# sourceMappingURL=pg-export.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pg-export.js","sourceRoot":"","sources":["../src/pg-export.ts"],"names":[],"mappings":";;;AAAA,iEAAqG;AAA5F,mHAAA,cAAc,OAAA;AAAsB,uHAAA,kBAAkB,OAAA"}
1
+ {"version":3,"file":"pg-export.js","sourceRoot":"","sources":["../src/pg-export.ts"],"names":[],"mappings":";;;AAAA,iEAAqG;AAA5F,mHAAA,cAAc,OAAA;AAAsB,uHAAA,kBAAkB,OAAA;AAC/D,qCAAiC;AAAxB,+FAAA,IAAI,OAAA"}
@@ -0,0 +1,21 @@
1
+ import { EntityManager } from "joist-core";
2
+ /**
3
+ * Seeds your local/test database with data created via the factories.
4
+ *
5
+ * Unlike `seed` from `joist-test-utils`, this defaults to the `PostgresDriver`, so you can just
6
+ * `import { seed } from "joist-orm/pg"` and pass only your seeding function.
7
+ *
8
+ * This will delete all data in the database, so is restricted to only `local` and `test`
9
+ * `NODE_ENV`s. We also assume the project does not require a context to seed.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { seed } from "joist-orm/pg";
14
+ *
15
+ * seed(async (em) => {
16
+ * // create your data via factories here
17
+ * });
18
+ * ```
19
+ */
20
+ export declare function seed<E extends EntityManager = EntityManager>(fn: (em: E) => Promise<void>): void;
21
+ //# sourceMappingURL=seed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.d.ts","sourceRoot":"","sources":["../src/seed.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAyB,MAAM,YAAY,CAAC;AAIlE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,IAAI,CAAC,CAAC,SAAS,aAAa,GAAG,aAAa,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAkBhG"}
package/build/seed.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.seed = seed;
7
+ const joist_core_1 = require("joist-core");
8
+ const pg_1 = __importDefault(require("pg"));
9
+ const PostgresDriver_js_1 = require("./drivers/PostgresDriver.js");
10
+ /**
11
+ * Seeds your local/test database with data created via the factories.
12
+ *
13
+ * Unlike `seed` from `joist-test-utils`, this defaults to the `PostgresDriver`, so you can just
14
+ * `import { seed } from "joist-orm/pg"` and pass only your seeding function.
15
+ *
16
+ * This will delete all data in the database, so is restricted to only `local` and `test`
17
+ * `NODE_ENV`s. We also assume the project does not require a context to seed.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { seed } from "joist-orm/pg";
22
+ *
23
+ * seed(async (em) => {
24
+ * // create your data via factories here
25
+ * });
26
+ * ```
27
+ */
28
+ function seed(fn) {
29
+ const env = process.env.NODE_ENV;
30
+ if (env !== "local" && env !== "test") {
31
+ throw new Error("seed will only run with NODE_ENV=local or NODE_ENV=test because it resets the database");
32
+ }
33
+ const pool = new pg_1.default.Pool((0, joist_core_1.newPgConnectionConfig)());
34
+ run(pool, fn)
35
+ .then(async () => {
36
+ console.log("Seeded!");
37
+ await pool.end();
38
+ })
39
+ .catch(async (err) => {
40
+ console.error(err);
41
+ await pool.end();
42
+ process.exit(1);
43
+ });
44
+ }
45
+ /** Flushes the database and runs `fn` against a fresh `EntityManager`. */
46
+ async function run(pool, fn) {
47
+ await pool.query("SELECT flush_database()");
48
+ const em = new joist_core_1.EntityManager({}, { driver: new PostgresDriver_js_1.PostgresDriver(pool) });
49
+ await fn(em);
50
+ await em.flush();
51
+ }
52
+ //# sourceMappingURL=seed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seed.js","sourceRoot":"","sources":["../src/seed.ts"],"names":[],"mappings":";;;;;AAsBA,oBAkBC;AAxCD,2CAAkE;AAClE,4CAAoB;AACpB,mEAA6D;AAE7D;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,IAAI,CAA0C,EAA4B;IACxF,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;IACjC,IAAI,GAAG,KAAK,OAAO,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CAAC,wFAAwF,CAAC,CAAC;IAC5G,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,YAAE,CAAC,IAAI,CAAC,IAAA,kCAAqB,GAAE,CAAC,CAAC;IAElD,GAAG,CAAI,IAAI,EAAE,EAAE,CAAC;SACb,IAAI,CAAC,KAAK,IAAI,EAAE;QACf,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACvB,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;IACnB,CAAC,CAAC;SACD,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QACnB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnB,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACP,CAAC;AAED,0EAA0E;AAC1E,KAAK,UAAU,GAAG,CAA0B,IAAa,EAAE,EAA4B;IACrF,MAAM,IAAI,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,MAAM,EAAE,GAAG,IAAI,0BAAa,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,kCAAc,CAAC,IAAI,CAAC,EAAE,CAAM,CAAC;IAC5E,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;IACb,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;AACnB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "joist-orm",
3
- "version": "2.3.0-next.2",
3
+ "version": "2.3.0-next.4",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -83,14 +83,14 @@
83
83
  "build"
84
84
  ],
85
85
  "dependencies": {
86
- "joist-codegen": "2.3.0-next.2",
87
- "joist-core": "2.3.0-next.2",
88
- "joist-graphql-codegen": "2.3.0-next.2",
89
- "joist-graphql-resolver-utils": "2.3.0-next.2",
90
- "joist-knex": "2.3.0-next.2",
91
- "joist-migration-utils": "2.3.0-next.2",
92
- "joist-test-utils": "2.3.0-next.2",
93
- "joist-utils": "2.3.0-next.2"
86
+ "joist-codegen": "2.3.0-next.4",
87
+ "joist-core": "2.3.0-next.4",
88
+ "joist-graphql-codegen": "2.3.0-next.4",
89
+ "joist-graphql-resolver-utils": "2.3.0-next.4",
90
+ "joist-knex": "2.3.0-next.4",
91
+ "joist-migration-utils": "2.3.0-next.4",
92
+ "joist-test-utils": "2.3.0-next.4",
93
+ "joist-utils": "2.3.0-next.4"
94
94
  },
95
95
  "peerDependencies": {
96
96
  "knex": "^3.1.0",