@cedarjs/cli-data-migrate 4.0.0-canary.13774 → 4.0.0-canary.13776

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.
package/dist/bin.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var L=Object.create;var w=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var U=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var v=(t,r)=>()=>(t&&(r=t(t=0)),r);var W=(t,r,e,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of R(r))!V.call(t,a)&&a!==e&&w(t,a,{get:()=>r[a],enumerable:!(i=N(r,a))||i.enumerable});return t};var f=(t,r,e)=>(e=t!=null?L(U(t)):{},W(r||!t||!t.__esModule?w(e,"default",{value:t,enumerable:!0}):e,t));var o,c,E=v(()=>{"use strict";o=f(require("ansis")),c={error:o.default.bold.red,warning:o.default.hex("#ffa500"),highlight:o.default.hex("#ffa500"),success:o.default.green,info:o.default.gray,bold:o.default.bold,underline:o.default.underline,note:o.default.blue,tip:o.default.green,important:o.default.magenta,caution:o.default.red,link:o.default.hex("#e8e8e8")}});async function $({importDbClientFromDist:t,distPath:r}){let e,i=!1;if(t){if(!l.default.existsSync(r)){console.warn(`Can't find api dist at ${r}. You may need to build first: yarn cedar build api`),process.exitCode=1;return}let d=g.default.join(r,"lib"),p=g.default.join(d,"db.js");if(!l.default.existsSync(p)){console.error(`Can't find db.js at ${p}. CedarJS expects the db.js file to be in the ${d} directory`),process.exitCode=1;return}e=(await import(p)).db}else(0,b.registerApiSideBabelHook)(),i=!0,e=require(g.default.join((0,u.getPaths)().api.lib,"db")).db;let a=await B(e);if(!a.length){console.info(c.success(`
3
- ${G}
4
- `)),process.exitCode=0;return}let s={run:0,skipped:0,error:0},n=a.map(d=>{let p=g.default.basename(d.path,".js");return{title:p,skip(){return s.error>0?(s.skipped++,!0):!1},async task(){i||(0,b.registerApiSideBabelHook)();try{let{startedAt:D,finishedAt:I}=await q(e,d.path);s.run++,await J(e,{version:d.version,name:p,startedAt:D,finishedAt:I})}catch(D){s.error++,console.error(c.error(`Error in data migration: ${D.message}`))}}}}),m=new S.Listr(n,{renderer:"verbose"});try{await m.run(),await e.$disconnect(),console.log(),j(s),console.log(),s.error&&(process.exitCode=1)}catch{process.exitCode=1,await e.$disconnect(),console.log(),j(s),console.log()}}async function B(t){let r=await(0,u.getDataMigrationsPath)((0,u.getPaths)().api.prismaConfig);if(!l.default.existsSync(r))return[];let e=l.default.readdirSync(r).filter(n=>["js",".ts"].some(m=>n.endsWith(m))).map(n=>{let[m]=n.split("-");return{version:m,path:g.default.join(r,n)}}),a=(await t.rW_DataMigration.findMany({orderBy:{version:"asc"}})).map(n=>n.version.toString());return e.filter(({version:n})=>!a.includes(n)).sort(H)}function H(t,r){let e=parseInt(t.version),i=parseInt(r.version);return e>i?1:e<i?-1:0}async function q(t,r){let e=require(r),i=new Date;return await e.default({db:t}),{startedAt:i,finishedAt:new Date}}async function J(t,{version:r,name:e,startedAt:i,finishedAt:a}){await t.rW_DataMigration.create({data:{version:r,name:e,startedAt:i,finishedAt:a}})}function j(t){t.run&&console.info(c.success(`${t.run} data migration(s) completed successfully.`)),t.error&&console.error(c.error(`${t.error} data migration(s) exited with errors.`)),t.skipped&&console.warn(c.warning(`${t.skipped} data migration(s) skipped due to previous error.`))}var l,g,S,b,u,G,O=v(()=>{"use strict";l=f(require("node:fs")),g=f(require("node:path")),S=require("listr2"),b=require("@cedarjs/babel-config"),u=require("@cedarjs/project-config");E();G="No pending data migrations run, already up-to-date."});var M=f(require("path")),P=require("dotenv-defaults"),_=require("yargs/helpers"),C=f(require("yargs/yargs")),y=require("@cedarjs/project-config");var x=require("termi-link"),h=require("@cedarjs/project-config");var k="Run any outstanding Data Migrations against the database";function A(t){return t.option("import-db-client-from-dist",{type:"boolean",alias:["db-from-dist"],description:"Import the db client from dist",default:!1}).option("dist-path",{type:"string",alias:"d",description:"Path to the api dist directory",default:(0,h.getPaths)().api.dist}).epilogue(`Also see the ${(0,x.terminalLink)("CedarJS CLI Reference","https://cedarjs.com/docs/cli-commands#datamigrate-up")}`)}O();process.env.REDWOOD_ENV_FILES_LOADED||((0,P.config)({path:M.default.join((0,y.getPaths)().base,".env"),defaults:M.default.join((0,y.getPaths)().base,".env.defaults"),multiline:!0}),process.env.REDWOOD_ENV_FILES_LOADED="true");(0,C.default)((0,_.hideBin)(process.argv)).scriptName("data-migrate").command("$0",k,A,$).parse();
2
+ "use strict";var _=Object.create;var y=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var L=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var R=(t,r)=>()=>(t&&(r=t(t=0)),r);var U=(t,r,i,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let e of I(r))!N.call(t,e)&&e!==i&&y(t,e,{get:()=>r[e],enumerable:!(a=C(r,e))||a.enumerable});return t};var l=(t,r,i)=>(i=t!=null?_(L(t)):{},U(r||!t||!t.__esModule?y(i,"default",{value:t,enumerable:!0}):i,t));async function E({importDbClientFromDist:t,distPath:r}){let i,a=!1;if(t){if(!g.default.existsSync(r)){console.warn(`Can't find api dist at ${r}. You may need to build first: yarn cedar build api`),process.exitCode=1;return}let s=p.default.join(r,"lib"),d=p.default.join(s,"db.js");if(!g.default.existsSync(d)){console.error(`Can't find db.js at ${d}. CedarJS expects the db.js file to be in the ${s} directory`),process.exitCode=1;return}i=(await import(d)).db}else(0,M.registerApiSideBabelHook)(),a=!0,i=require(p.default.join((0,f.getPaths)().api.lib,"db")).db;let e=await V(i);if(!e.length){console.info(c.colors.success(`
3
+ ${H}
4
+ `)),process.exitCode=0;return}let n={run:0,skipped:0,error:0},o=e.map(s=>{let d=p.default.basename(s.path,".js");return{title:d,skip(){return n.error>0?(n.skipped++,!0):!1},async task(){a||(0,M.registerApiSideBabelHook)();try{let{startedAt:u,finishedAt:P}=await B(i,s.path);n.run++,await q(i,{version:s.version,name:d,startedAt:u,finishedAt:P})}catch(u){n.error++,console.error(c.colors.error(`Error in data migration: ${u.message}`))}}}}),m=new A.Listr(o,{renderer:"verbose"});try{await m.run(),await i.$disconnect(),console.log(),k(n),console.log(),n.error&&(process.exitCode=1)}catch{process.exitCode=1,await i.$disconnect(),console.log(),k(n),console.log()}}async function V(t){let r=await(0,f.getDataMigrationsPath)((0,f.getPaths)().api.prismaConfig);if(!g.default.existsSync(r))return[];let i=g.default.readdirSync(r).filter(o=>["js",".ts"].some(m=>o.endsWith(m))).map(o=>{let[m]=o.split("-");return{version:m,path:p.default.join(r,o)}}),e=(await t.rW_DataMigration.findMany({orderBy:{version:"asc"}})).map(o=>o.version.toString());return i.filter(({version:o})=>!e.includes(o)).sort(W)}function W(t,r){let i=parseInt(t.version),a=parseInt(r.version);return i>a?1:i<a?-1:0}async function B(t,r){let i=require(r),a=new Date;return await i.default({db:t}),{startedAt:a,finishedAt:new Date}}async function q(t,{version:r,name:i,startedAt:a,finishedAt:e}){await t.rW_DataMigration.create({data:{version:r,name:i,startedAt:a,finishedAt:e}})}function k(t){t.run&&console.info(c.colors.success(`${t.run} data migration(s) completed successfully.`)),t.error&&console.error(c.colors.error(`${t.error} data migration(s) exited with errors.`)),t.skipped&&console.warn(c.colors.warning(`${t.skipped} data migration(s) skipped due to previous error.`))}var g,p,A,M,c,f,H,j=R(()=>{"use strict";g=l(require("node:fs")),p=l(require("node:path")),A=require("listr2"),M=require("@cedarjs/babel-config"),c=require("@cedarjs/cli-helpers"),f=require("@cedarjs/project-config");H="No pending data migrations run, already up-to-date."});var b=l(require("path")),S=require("dotenv-defaults"),$=require("yargs/helpers"),O=l(require("yargs/yargs")),h=require("@cedarjs/project-config");var w=require("termi-link"),D=require("@cedarjs/project-config");var v="Run any outstanding Data Migrations against the database";function x(t){return t.option("import-db-client-from-dist",{type:"boolean",alias:["db-from-dist"],description:"Import the db client from dist",default:!1}).option("dist-path",{type:"string",alias:"d",description:"Path to the api dist directory",default:(0,D.getPaths)().api.dist}).epilogue(`Also see the ${(0,w.terminalLink)("CedarJS CLI Reference","https://cedarjs.com/docs/cli-commands#datamigrate-up")}`)}j();process.env.REDWOOD_ENV_FILES_LOADED||((0,S.config)({path:b.default.join((0,h.getPaths)().base,".env"),defaults:b.default.join((0,h.getPaths)().base,".env.defaults"),multiline:!0}),process.env.REDWOOD_ENV_FILES_LOADED="true");(0,O.default)((0,$.hideBin)(process.argv)).scriptName("data-migrate").command("$0",v,x,E).parse();
@@ -1 +1 @@
1
- {"version":3,"file":"installHandler.d.ts","sourceRoot":"","sources":["../../src/commands/installHandler.ts"],"names":[],"mappings":"AAcA,wBAAsB,OAAO,kBAmD5B;AAED,eAAO,MAAM,uBAAuB,8HAMlC,CAAA;AAEF,eAAO,MAAM,8BAA8B,8EACkC,CAAA;AAE7E,eAAO,MAAM,KAAK,QAMN,CAAA"}
1
+ {"version":3,"file":"installHandler.d.ts","sourceRoot":"","sources":["../../src/commands/installHandler.ts"],"names":[],"mappings":"AAaA,wBAAsB,OAAO,kBAmD5B;AAED,eAAO,MAAM,uBAAuB,8HAMlC,CAAA;AAEF,eAAO,MAAM,8BAA8B,8EACkC,CAAA;AAE7E,eAAO,MAAM,KAAK,QAMN,CAAA"}
@@ -38,8 +38,8 @@ var import_node_fs = __toESM(require("node:fs"));
38
38
  var import_node_path = __toESM(require("node:path"));
39
39
  var import_execa = __toESM(require("execa"));
40
40
  var import_listr2 = require("listr2");
41
+ var import_cli_helpers = require("@cedarjs/cli-helpers");
41
42
  var import_project_config = require("@cedarjs/project-config");
42
- var import_colors = __toESM(require("../lib/colors"));
43
43
  async function handler() {
44
44
  const cedarProjectPaths = (0, import_project_config.getPaths)();
45
45
  const prismaConfigPath = cedarProjectPaths.api.prismaConfig;
@@ -86,7 +86,7 @@ async function handler() {
86
86
  console.log(notes);
87
87
  } catch (e) {
88
88
  process.exitCode = 1;
89
- console.error(import_colors.default.error(e.message));
89
+ console.error(import_cli_helpers.colors.error(e.message));
90
90
  }
91
91
  }
92
92
  const RW_DATA_MIGRATION_MODEL = `model RW_DataMigration {
@@ -98,9 +98,9 @@ const RW_DATA_MIGRATION_MODEL = `model RW_DataMigration {
98
98
  const createDatabaseMigrationCommand = "yarn cedar prisma migrate dev --name create_data_migrations --create-only";
99
99
  const notes = [
100
100
  "",
101
- import_colors.default.warning("Don't forget to apply the migration when you're ready:"),
101
+ import_cli_helpers.colors.warning("Don't forget to apply the migration when you're ready:"),
102
102
  "",
103
- ` ${import_colors.default.bold("yarn cedar prisma migrate dev")}`,
103
+ ` ${import_cli_helpers.colors.bold("yarn cedar prisma migrate dev")}`,
104
104
  ""
105
105
  ].join("\n");
106
106
  // Annotate the CommonJS export names for ESM import in node:
@@ -36,8 +36,8 @@ var import_node_fs = __toESM(require("node:fs"));
36
36
  var import_node_path = __toESM(require("node:path"));
37
37
  var import_listr2 = require("listr2");
38
38
  var import_babel_config = require("@cedarjs/babel-config");
39
+ var import_cli_helpers = require("@cedarjs/cli-helpers");
39
40
  var import_project_config = require("@cedarjs/project-config");
40
- var import_colors = __toESM(require("../lib/colors"));
41
41
  async function handler({
42
42
  importDbClientFromDist,
43
43
  distPath
@@ -69,7 +69,7 @@ async function handler({
69
69
  }
70
70
  const pendingDataMigrations = await getPendingDataMigrations(db);
71
71
  if (!pendingDataMigrations.length) {
72
- console.info(import_colors.default.success(`
72
+ console.info(import_cli_helpers.colors.success(`
73
73
  ${NO_PENDING_MIGRATIONS_MESSAGE}
74
74
  `));
75
75
  process.exitCode = 0;
@@ -107,7 +107,7 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
107
107
  } catch (e) {
108
108
  counters.error++;
109
109
  console.error(
110
- import_colors.default.error(`Error in data migration: ${e.message}`)
110
+ import_cli_helpers.colors.error(`Error in data migration: ${e.message}`)
111
111
  );
112
112
  }
113
113
  }
@@ -191,17 +191,17 @@ async function recordDataMigration(db, { version, name, startedAt, finishedAt })
191
191
  function reportDataMigrations(counters) {
192
192
  if (counters.run) {
193
193
  console.info(
194
- import_colors.default.success(`${counters.run} data migration(s) completed successfully.`)
194
+ import_cli_helpers.colors.success(`${counters.run} data migration(s) completed successfully.`)
195
195
  );
196
196
  }
197
197
  if (counters.error) {
198
198
  console.error(
199
- import_colors.default.error(`${counters.error} data migration(s) exited with errors.`)
199
+ import_cli_helpers.colors.error(`${counters.error} data migration(s) exited with errors.`)
200
200
  );
201
201
  }
202
202
  if (counters.skipped) {
203
203
  console.warn(
204
- import_colors.default.warning(
204
+ import_cli_helpers.colors.warning(
205
205
  `${counters.skipped} data migration(s) skipped due to previous error.`
206
206
  )
207
207
  );
@@ -36,8 +36,8 @@ var import_node_fs = __toESM(require("node:fs"));
36
36
  var import_node_path = __toESM(require("node:path"));
37
37
  var import_bundle_require = require("bundle-require");
38
38
  var import_listr2 = require("listr2");
39
+ var import_cli_helpers = require("@cedarjs/cli-helpers");
39
40
  var import_project_config = require("@cedarjs/project-config");
40
- var import_colors = __toESM(require("../lib/colors"));
41
41
  async function handler({
42
42
  importDbClientFromDist,
43
43
  distPath
@@ -76,7 +76,7 @@ async function handler({
76
76
  }
77
77
  const pendingDataMigrations = await getPendingDataMigrations(db);
78
78
  if (!pendingDataMigrations.length) {
79
- console.info(import_colors.default.success(`
79
+ console.info(import_cli_helpers.colors.success(`
80
80
  ${NO_PENDING_MIGRATIONS_MESSAGE}
81
81
  `));
82
82
  process.exitCode = 0;
@@ -111,7 +111,7 @@ ${NO_PENDING_MIGRATIONS_MESSAGE}
111
111
  } catch (e) {
112
112
  counters.error++;
113
113
  console.error(
114
- import_colors.default.error(`Error in data migration: ${e.message}`)
114
+ import_cli_helpers.colors.error(`Error in data migration: ${e.message}`)
115
115
  );
116
116
  }
117
117
  }
@@ -199,17 +199,17 @@ async function recordDataMigration(db, { version, name, startedAt, finishedAt })
199
199
  function reportDataMigrations(counters) {
200
200
  if (counters.run) {
201
201
  console.info(
202
- import_colors.default.success(`${counters.run} data migration(s) completed successfully.`)
202
+ import_cli_helpers.colors.success(`${counters.run} data migration(s) completed successfully.`)
203
203
  );
204
204
  }
205
205
  if (counters.error) {
206
206
  console.error(
207
- import_colors.default.error(`${counters.error} data migration(s) exited with errors.`)
207
+ import_cli_helpers.colors.error(`${counters.error} data migration(s) exited with errors.`)
208
208
  );
209
209
  }
210
210
  if (counters.skipped) {
211
211
  console.warn(
212
- import_colors.default.warning(
212
+ import_cli_helpers.colors.warning(
213
213
  `${counters.skipped} data migration(s) skipped due to previous error.`
214
214
  )
215
215
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cedarjs/cli-data-migrate",
3
- "version": "4.0.0-canary.13774+7a826c6c1",
3
+ "version": "4.0.0-canary.13776+c89b50442",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/cedarjs/cedar.git",
@@ -26,9 +26,9 @@
26
26
  "test:unit": "vitest run src"
27
27
  },
28
28
  "dependencies": {
29
- "@cedarjs/babel-config": "4.0.0-canary.13774",
30
- "@cedarjs/project-config": "4.0.0-canary.13774",
31
- "ansis": "4.2.0",
29
+ "@cedarjs/babel-config": "4.0.0-canary.13776",
30
+ "@cedarjs/cli-helpers": "4.0.0-canary.13776",
31
+ "@cedarjs/project-config": "4.0.0-canary.13776",
32
32
  "bundle-require": "^5.1.0",
33
33
  "dotenv-defaults": "5.0.2",
34
34
  "execa": "5.1.1",
@@ -37,7 +37,7 @@
37
37
  "yargs": "17.7.2"
38
38
  },
39
39
  "devDependencies": {
40
- "@cedarjs/framework-tools": "4.0.0-canary.13774",
40
+ "@cedarjs/framework-tools": "4.0.0-canary.13776",
41
41
  "@prisma/client": "7.6.0",
42
42
  "@types/yargs": "17.0.35",
43
43
  "memfs": "4.57.1",
@@ -51,5 +51,5 @@
51
51
  "publishConfig": {
52
52
  "access": "public"
53
53
  },
54
- "gitHead": "7a826c6c1826f7116464b23d39631e0faef8d500"
54
+ "gitHead": "c89b504429437540b873e933d678d021e855cd48"
55
55
  }
@@ -1,16 +0,0 @@
1
- declare const _default: {
2
- error: import("ansis", { with: { "resolution-mode": "import" } }).Ansis;
3
- warning: import("ansis", { with: { "resolution-mode": "import" } }).Ansis;
4
- highlight: import("ansis", { with: { "resolution-mode": "import" } }).Ansis;
5
- success: import("ansis", { with: { "resolution-mode": "import" } }).Ansis;
6
- info: import("ansis", { with: { "resolution-mode": "import" } }).Ansis;
7
- bold: import("ansis", { with: { "resolution-mode": "import" } }).Ansis;
8
- underline: import("ansis", { with: { "resolution-mode": "import" } }).Ansis;
9
- note: import("ansis", { with: { "resolution-mode": "import" } }).Ansis;
10
- tip: import("ansis", { with: { "resolution-mode": "import" } }).Ansis;
11
- important: import("ansis", { with: { "resolution-mode": "import" } }).Ansis;
12
- caution: import("ansis", { with: { "resolution-mode": "import" } }).Ansis;
13
- link: import("ansis", { with: { "resolution-mode": "import" } }).Ansis;
14
- };
15
- export default _default;
16
- //# sourceMappingURL=colors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../../src/lib/colors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAKA,wBAaC"}
@@ -1,48 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var colors_exports = {};
30
- __export(colors_exports, {
31
- default: () => colors_default
32
- });
33
- module.exports = __toCommonJS(colors_exports);
34
- var import_ansis = __toESM(require("ansis"));
35
- var colors_default = {
36
- error: import_ansis.default.bold.red,
37
- warning: import_ansis.default.hex("#ffa500"),
38
- highlight: import_ansis.default.hex("#ffa500"),
39
- success: import_ansis.default.green,
40
- info: import_ansis.default.gray,
41
- bold: import_ansis.default.bold,
42
- underline: import_ansis.default.underline,
43
- note: import_ansis.default.blue,
44
- tip: import_ansis.default.green,
45
- important: import_ansis.default.magenta,
46
- caution: import_ansis.default.red,
47
- link: import_ansis.default.hex("#e8e8e8")
48
- };