@yongdall/migrate 0.1.0

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/bin.mjs ADDED
@@ -0,0 +1,19 @@
1
+ import { stop } from "@yongdall/connection";
2
+ import "@yongdall/init";
3
+ import migrate from "#index";
4
+
5
+ //#region cli/migrate/bin.mjs
6
+ let args = process.argv.slice(2);
7
+ let index = args.indexOf("--");
8
+ if (index >= 0) args = args.slice(0, index);
9
+ const domain = args.find((v) => v.startsWith("--domain="))?.slice(9) || "";
10
+ const plugins = [...args.filter((v) => v.startsWith("--plugin=")).map((v) => v.slice(9)), ...args.filter((v) => v.startsWith("--plugins=")).map((v) => v.slice(10))].flatMap((v) => v.split(",")).filter(Boolean);
11
+ const database = args.find((v) => v.startsWith("--database="))?.slice(11);
12
+ migrate({
13
+ domain,
14
+ plugins,
15
+ database
16
+ }).then(stop);
17
+
18
+ //#endregion
19
+ //# sourceMappingURL=bin.mjs.map
package/bin.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.mjs","names":[],"sources":["../../cli/migrate/bin.mjs"],"sourcesContent":["import { stop } from '@yongdall/connection';\nimport '@yongdall/init';\nimport migrate from '#index';\n\n\n\nlet args = process.argv.slice(2);\nlet index = args.indexOf('--');\nif (index >= 0) {\n\targs = args.slice(0, index);\n}\n\nconst domain = args.find(v => v.startsWith('--domain='))?.slice('--domain='.length) || ''\n\nconst plugins = [\n\t...args.filter(v => v.startsWith('--plugin=')).map(v => v.slice('--plugin='.length)),\n\t...args.filter(v => v.startsWith('--plugins=')).map(v => v.slice('--plugins='.length)),\n].flatMap(v => v.split(',')).filter(Boolean)\nconst database = args.find(v => v.startsWith('--database='))?.slice('--database='.length)\nmigrate({ domain, plugins, database }).then(stop);\n"],"mappings":";;;;;AAMA,IAAI,OAAO,QAAQ,KAAK,MAAM,EAAE;AAChC,IAAI,QAAQ,KAAK,QAAQ,KAAK;AAC9B,IAAI,SAAS,EACZ,QAAO,KAAK,MAAM,GAAG,MAAM;AAG5B,MAAM,SAAS,KAAK,MAAK,MAAK,EAAE,WAAW,YAAY,CAAC,EAAE,MAAM,EAAmB,IAAI;AAEvF,MAAM,UAAU,CACf,GAAG,KAAK,QAAO,MAAK,EAAE,WAAW,YAAY,CAAC,CAAC,KAAI,MAAK,EAAE,MAAM,EAAmB,CAAC,EACpF,GAAG,KAAK,QAAO,MAAK,EAAE,WAAW,aAAa,CAAC,CAAC,KAAI,MAAK,EAAE,MAAM,GAAoB,CAAC,CACtF,CAAC,SAAQ,MAAK,EAAE,MAAM,IAAI,CAAC,CAAC,OAAO,QAAQ;AAC5C,MAAM,WAAW,KAAK,MAAK,MAAK,EAAE,WAAW,cAAc,CAAC,EAAE,MAAM,GAAqB;AACzF,QAAQ;CAAE;CAAQ;CAAS;CAAU,CAAC,CAAC,KAAK,KAAK"}
package/index.d.mts ADDED
@@ -0,0 +1,20 @@
1
+ //#region cli/migrate/index.d.mts
2
+ /**
3
+ *
4
+ * @param {object} [options]
5
+ * @param {string[]} [options.plugins]
6
+ * @param {string} [options.database]
7
+ * @param {string} [options.domain]
8
+ * @returns {Promise<void>}
9
+ */
10
+ declare function _default({
11
+ plugins,
12
+ database,
13
+ domain
14
+ }?: {
15
+ plugins?: string[] | undefined;
16
+ database?: string | undefined;
17
+ domain?: string | undefined;
18
+ }): Promise<void>;
19
+ //#endregion
20
+ export { _default as default };
package/index.mjs ADDED
@@ -0,0 +1,33 @@
1
+ import { connect } from "@yongdall/connection";
2
+ import { hooks } from "@yongdall/core";
3
+ import { _run } from "@yongdall/context";
4
+
5
+ //#region cli/migrate/index.mjs
6
+ /**
7
+ *
8
+ * @param {object} [options]
9
+ * @param {string[]} [options.plugins]
10
+ * @param {string} [options.database]
11
+ * @param {string} [options.domain]
12
+ * @returns {Promise<void>}
13
+ */
14
+ async function migrate_default({ plugins, database, domain } = {}) {
15
+ const list = [...new Set(plugins?.length ? [...hooks.get("migrationModels").entries()].filter((v) => plugins.includes(v[0])).map((v) => v[1]) : [...hooks.get("migrationModels").values()].filter(Boolean))];
16
+ return _run({ domain: domain || "" }, async () => {
17
+ if (typeof database === "string") {
18
+ const id = ["-_/"].includes(database) ? "" : database;
19
+ const models = list.filter((v) => (v.databaseId || "") === id);
20
+ await connect("rdb", id).transaction((t) => t.syncTables(models));
21
+ return;
22
+ }
23
+ const models = Object.groupBy(list, (d) => d.databaseId || "");
24
+ for (const [databaseId, list] of Object.entries(models)) {
25
+ if (!list) continue;
26
+ await connect("rdb", databaseId).transaction((t) => t.syncTables(list));
27
+ }
28
+ });
29
+ }
30
+
31
+ //#endregion
32
+ export { migrate_default as default };
33
+ //# sourceMappingURL=index.mjs.map
package/index.mjs.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../cli/migrate/index.mjs"],"sourcesContent":["import { connect } from '@yongdall/connection';\nimport { hooks } from '@yongdall/core';\nimport { _run } from '@yongdall/context';\n\n\n/**\n * \n * @param {object} [options]\n * @param {string[]} [options.plugins]\n * @param {string} [options.database] \n * @param {string} [options.domain] \n * @returns {Promise<void>}\n */\nexport default async function ({\n\tplugins, database, domain\n} = {}) {\n\tconst list = [...new Set(plugins?.length\n\t\t? [...hooks.get('migrationModels').entries()]\n\t\t\t.filter(v => plugins.includes(v[0])).map((v) => v[1])\n\t\t: [...hooks.get('migrationModels').values()].filter(Boolean))];\n\treturn _run({domain: domain || ''}, async () => {\n\t\tif (typeof database === 'string') {\n\t\t\tconst id = ['-_/'].includes(database) ? '' : database;\n\t\t\tconst models = list.filter(v => (v.databaseId || '') === id);\n\t\t\tawait connect('rdb', id).transaction(t => t.syncTables(models));\n\t\t\treturn;\n\t\t}\n\t\tconst models = Object.groupBy(list, d => d.databaseId || '');\n\t\tfor (const [databaseId, list] of Object.entries(models)) {\n\t\t\tif (!list) { continue; }\n\t\t\tawait connect('rdb', databaseId).transaction(t => t.syncTables(list));\n\t\t}\n\n\t});\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,+BAA+B,EAC9B,SAAS,UAAU,WAChB,EAAE,EAAE;CACP,MAAM,OAAO,CAAC,GAAG,IAAI,IAAI,SAAS,SAC/B,CAAC,GAAG,MAAM,IAAI,kBAAkB,CAAC,SAAS,CAAC,CAC3C,QAAO,MAAK,QAAQ,SAAS,EAAE,GAAG,CAAC,CAAC,KAAK,MAAM,EAAE,GAAG,GACpD,CAAC,GAAG,MAAM,IAAI,kBAAkB,CAAC,QAAQ,CAAC,CAAC,OAAO,QAAQ,CAAC,CAAC;AAC/D,QAAO,KAAK,EAAC,QAAQ,UAAU,IAAG,EAAE,YAAY;AAC/C,MAAI,OAAO,aAAa,UAAU;GACjC,MAAM,KAAK,CAAC,MAAM,CAAC,SAAS,SAAS,GAAG,KAAK;GAC7C,MAAM,SAAS,KAAK,QAAO,OAAM,EAAE,cAAc,QAAQ,GAAG;AAC5D,SAAM,QAAQ,OAAO,GAAG,CAAC,aAAY,MAAK,EAAE,WAAW,OAAO,CAAC;AAC/D;;EAED,MAAM,SAAS,OAAO,QAAQ,OAAM,MAAK,EAAE,cAAc,GAAG;AAC5D,OAAK,MAAM,CAAC,YAAY,SAAS,OAAO,QAAQ,OAAO,EAAE;AACxD,OAAI,CAAC,KAAQ;AACb,SAAM,QAAQ,OAAO,WAAW,CAAC,aAAY,MAAK,EAAE,WAAW,KAAK,CAAC;;GAGrE"}
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@yongdall/migrate",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "bin": {
6
+ "migrate.yongdall": "./bin.mjs"
7
+ },
8
+ "main": "./index.mjs",
9
+ "imports": {
10
+ "#index": "./index.mjs"
11
+ },
12
+ "dependencies": {
13
+ "@yongdall/plugins": "^0.1.0",
14
+ "@yongdall/context": "^0.1.0",
15
+ "@yongdall/core": "^0.1.0",
16
+ "@yongdall/init": "^0.1.0",
17
+ "@yongdall/connection": "^0.1.0"
18
+ },
19
+ "exports": {
20
+ ".": "./index.mjs"
21
+ }
22
+ }