@aurios/mizzling 1.1.6 → 1.1.7
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/.turbo/turbo-build.log +4 -4
- package/dist/chunk-NASE45GS.js +2 -0
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/src/config.ts +13 -4
- package/dist/chunk-DKDRM5WU.js +0 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @aurios/mizzling@1.1.
|
|
2
|
+
> @aurios/mizzling@1.1.7 build /home/runner/work/mizzle/mizzle/packages/mizzling
|
|
3
3
|
> tsup
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/cli.ts, src/index.ts
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
[34mESM[39m Build start
|
|
12
12
|
[32mESM[39m [1mdist/cli.js [22m[32m13.77 KB[39m
|
|
13
13
|
[32mESM[39m [1mdist/index.js [22m[32m87.00 B[39m
|
|
14
|
-
[32mESM[39m [1mdist/chunk-
|
|
15
|
-
[32mESM[39m ⚡️ Build success in
|
|
14
|
+
[32mESM[39m [1mdist/chunk-NASE45GS.js [22m[32m1.89 KB[39m
|
|
15
|
+
[32mESM[39m ⚡️ Build success in 51ms
|
|
16
16
|
[34mDTS[39m Build start
|
|
17
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
+
[32mDTS[39m ⚡️ Build success in 2415ms
|
|
18
18
|
[32mDTS[39m [1mdist/cli.d.ts [22m[32m13.00 B[39m
|
|
19
19
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m2.07 KB[39m
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import{join as s}from"path";import{existsSync as c}from"fs";import{DynamoDBClient as a}from"@aws-sdk/client-dynamodb";import{fromIni as f}from"@aws-sdk/credential-provider-ini";import{NodeHttpHandler as l}from"@smithy/node-http-handler";import p from"http";import m from"https";function v(e){return e}function h(e){let r={keepAlive:!0,maxSockets:1/0},o={region:e.region||"us-east-1",endpoint:e.endpoint,maxAttempts:e.maxAttempts,requestHandler:new l({httpAgent:new p.Agent(r),httpsAgent:new m.Agent(r)})};return e.credentials?o.credentials=e.credentials:e.profile?o.credentials=f({profile:e.profile}):e.endpoint&&(e.endpoint.includes("localhost")||e.endpoint.includes("127.0.0.1"))&&(o.credentials={accessKeyId:"local",secretAccessKey:"local"}),new a(o)}async function M(e){let o=process.env.MIZZLE_CONFIG;if(!o){let n=s(process.cwd(),e||"mizzle.config.ts"),t=s(process.cwd(),e||"mizzle.config.js");if(c(n))o=n;else if(c(t))o=t;else throw new Error(`Could not find ${e||"mizzle.config.ts/js"} in current directory.`)}try{let n=await import(o),t=n.default||n;if(!t||typeof t!="object")throw new Error("Invalid config: default export must be an object");if(!t.schema)throw new Error("Invalid config: missing 'schema' path");if(!t.out)throw new Error("Invalid config: missing 'out' directory");let i={...t};return process.env.MIZZLE_REGION&&(i.region=process.env.MIZZLE_REGION),process.env.MIZZLE_ENDPOINT&&(i.endpoint=process.env.MIZZLE_ENDPOINT),process.env.MIZZLE_SCHEMA&&(i.schema=process.env.MIZZLE_SCHEMA),process.env.MIZZLE_OUT&&(i.out=process.env.MIZZLE_OUT),process.env.MIZZLE_VERBOSE&&(i.verbose=process.env.MIZZLE_VERBOSE==="true"),process.env.MIZZLE_STRICT&&(i.strict=process.env.MIZZLE_STRICT==="true"),i}catch(n){if(n instanceof Error&&n.message.startsWith("Invalid config"))throw n;let t=n instanceof Error?n.message:String(n);throw new Error(`Failed to load config: ${t}`)}}export{v as a,h as b,M as c};
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{b,c as N}from"./chunk-
|
|
2
|
+
import{b,c as N}from"./chunk-NASE45GS.js";import{Command as Qe}from"commander";import*as x from"@clack/prompts";var p={COLUMNS:Symbol.for("mizzle:Columns"),INDEXES:Symbol.for("mizzle:Indexes"),SORT_KEY:Symbol.for("mizzle:SortKey"),TABLE_NAME:Symbol.for("mizzle:TableName"),PARTITION_KEY:Symbol.for("mizzle:PartitionKey")},c={ENTITY_NAME:Symbol.for("mizzle:EntityName"),ENTITY_STRATEGY:Symbol.for("mizzle:EntityStrategy"),PHYSICAL_TABLE:Symbol.for("mizzle:PhysicalTable"),COLUMNS:Symbol.for("mizzle:Columns"),ENTITY_KIND:Symbol.for("mizzle:EntityKind")};var I=class{[p.TABLE_NAME]="";[p.INDEXES]=void 0;[p.PARTITION_KEY]={};[p.SORT_KEY]=void 0;static Symbol=p;constructor(n,t){this[p.TABLE_NAME]=n,this[p.PARTITION_KEY]=t.pk.build(this),this[p.SORT_KEY]=t.sk?t.sk.build(this):void 0,this[p.INDEXES]=t.indexes}},D=class{[c.ENTITY_NAME]="";[c.PHYSICAL_TABLE]={};[c.COLUMNS]={};[c.ENTITY_STRATEGY]={};static Symbol=c;constructor(n,t,o,a){this[c.ENTITY_NAME]=n,this[c.PHYSICAL_TABLE]=t,this[c.COLUMNS]=o,this[c.ENTITY_STRATEGY]=a}};import ue from"fast-glob";import{stat as pe}from"fs/promises";import{resolve as ce}from"path";async function E(e){let n=Array.isArray(e.schema)?e.schema:[e.schema],t=[],o=[],a=new Set,i=async r=>{let l=ce(process.cwd(),r);if(!a.has(l)){a.add(l);try{let s=await import(l);for(let u in s){let m=s[u];!m||typeof m!="object"||(m instanceof I||m[p.TABLE_NAME]!==void 0?t.push(m):(m instanceof D||m[c.ENTITY_NAME]!==void 0)&&o.push(m))}}catch(s){console.warn(`Failed to import schema file: ${l}`,s)}}};for(let r of n){let l=r,s=!1;try{let m=await pe(r);m.isDirectory()?l=`${r}/**/*.{ts,js,tsx,jsx}`:m.isFile()&&(s=!0)}catch{}if(s){await i(r);continue}let u=await ue(l,{absolute:!0});for(let m of u)await i(m)}return{tables:t,entities:o}}import{join as _}from"path";import{writeFile as de,readFile as Te,mkdir as fe,readdir as ye}from"fs/promises";import{existsSync as z}from"fs";var U="snapshot.json";async function j(e,n){z(e)||await fe(e,{recursive:!0});let t=_(e,U);await de(t,JSON.stringify(n,null,2),"utf-8")}async function v(e){let n=_(e,U);if(!z(n))return null;let t=await Te(n,"utf-8");return JSON.parse(t)}function M(e){let n={};for(let t of e.tables){let o=e.entities.filter(i=>i[c.PHYSICAL_TABLE]===t),a=Ce(t,o);n[a.TableName]=a}return{version:"1",tables:n}}async function Y(e){if(!z(e))return"0000";let n=await ye(e),t=-1;for(let o of n){if(!o.endsWith(".ts"))continue;let a=o.match(/^(\d{4})_/);if(a){let i=parseInt(a[1],10);i>t&&(t=i)}}return t===-1?"0000":(t+1).toString().padStart(4,"0")}function Ce(e,n){let t=e[p.TABLE_NAME],o=new Map,a=e[p.PARTITION_KEY];o.set(a.name,a.getDynamoType());let i=e[p.SORT_KEY];i&&o.set(i.name,i.getDynamoType());let r=[{AttributeName:a.name,KeyType:"HASH"}];i&&r.push({AttributeName:i.name,KeyType:"RANGE"});let l=[],s=[],u=e[p.INDEXES]||{};for(let[T,f]of Object.entries(u)){let P=f.type,d=f.config;if(P==="gsi"){if(d.pk){let S=O(d.pk,e,n);o.set(d.pk,S)}if(d.sk){let S=O(d.sk,e,n);o.set(d.sk,S)}let B={IndexName:T,KeySchema:[{AttributeName:d.pk,KeyType:"HASH"}],Projection:{ProjectionType:"ALL"}};d.sk&&B.KeySchema.push({AttributeName:d.sk,KeyType:"RANGE"}),l.push(B)}else if(P==="lsi"){if(d.sk){let S=O(d.sk,e,n);o.set(d.sk,S)}let B={IndexName:T,KeySchema:[{AttributeName:a.name,KeyType:"HASH"},{AttributeName:d.sk,KeyType:"RANGE"}],Projection:{ProjectionType:"ALL"}};s.push(B)}}let m=Array.from(o.entries()).map(([T,f])=>({AttributeName:T,AttributeType:f})).sort((T,f)=>T.AttributeName.localeCompare(f.AttributeName));l.sort((T,f)=>(T.IndexName||"").localeCompare(f.IndexName||"")),s.sort((T,f)=>(T.IndexName||"").localeCompare(f.IndexName||""));let h={TableName:t,AttributeDefinitions:m,KeySchema:r};return l.length>0&&(h.GlobalSecondaryIndexes=l),s.length>0&&(h.LocalSecondaryIndexes=s),h}function O(e,n,t){let o=n[p.PARTITION_KEY];if(o.name===e)return o.getDynamoType();let a=n[p.SORT_KEY];if(a&&a.name===e)return a.getDynamoType();for(let i of t){let r=i[c.COLUMNS];if(r){let l=r[e];if(l)return l.getDynamoType()}}throw new Error(`Could not resolve type for column '${e}' in table '${n[p.TABLE_NAME]}'. Ensure it is defined in an Entity.`)}function A(e,n){let t=[],a=M(e).tables,i=n.tables||{},r=new Set([...Object.keys(a),...Object.keys(i)]);for(let l of r){let s=a[l],u=i[l];s&&!u?t.push({type:"create",table:s}):!s&&u?t.push({type:"delete",tableName:l}):s&&u&&(ge(s,u)||t.push({type:"update",tableName:l,changes:["Changed"]}))}return t}function ge(e,n){let t=o=>{let a={...o};return a.AttributeDefinitions=[...a.AttributeDefinitions||[]].sort((i,r)=>(i.AttributeName||"").localeCompare(r.AttributeName||"")),a.GlobalSecondaryIndexes&&(a.GlobalSecondaryIndexes=[...a.GlobalSecondaryIndexes].sort((i,r)=>(i.IndexName||"").localeCompare(r.IndexName||""))),a.LocalSecondaryIndexes&&(a.LocalSecondaryIndexes=[...a.LocalSecondaryIndexes].sort((i,r)=>(i.IndexName||"").localeCompare(r.IndexName||""))),a};return JSON.stringify(t(e))===JSON.stringify(t(n))}import{join as be}from"path";import{writeFile as xe,mkdir as he}from"fs/promises";import{existsSync as Se}from"fs";import{text as Ne,isCancel as Be,cancel as Ie,intro as De,outro as $}from"@clack/prompts";async function F(e){De("Mizzle Generate");let{config:n}=e,t=e.discoverSchema||E;try{let o=await t(n),a=n.out,i=await v(a)||{version:"0",tables:{}},r=M(o),l=A(o,i);if(l.length===0){$("No changes detected.");return}console.log(`Detected ${l.length} changes.`);let s=await Y(a),u=e.name;if(u||(u=await Ne({message:"Enter migration name",placeholder:"init",initialValue:"migration",validate(f){if(f.length===0)return"Name is required"}})),Be(u)){Ie("Operation cancelled.");return}let m=`${s}_${u}.ts`;Se(a)||await he(a,{recursive:!0});let h=be(a,m),T=Ee(l);await xe(h,T),console.log(`Created migration: ${m}`),await j(a,r),$("Updated snapshot.json")}catch(o){console.error("Error generating migration:",o),process.exit(1)}}function Ee(e){let n=[],t=[];for(let o of e)o.type==="create"?(n.push(`// Create Table: ${o.table.TableName}`),n.push(`await db.createTable("${o.table.TableName}", ${JSON.stringify(o.table,null,2)});
|
|
3
3
|
`),t.unshift(`// Drop Table: ${o.table.TableName}`),t.unshift(`await db.deleteTable("${o.table.TableName}");
|
|
4
4
|
`)):o.type==="delete"?(n.push(`// Drop Table: ${o.tableName}`),n.push(`await db.deleteTable("${o.tableName}");
|
|
5
5
|
`),t.unshift(`// Create Table: ${o.tableName}`),t.unshift(`// TODO: Restore table definition for rollback
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as e}from"./chunk-
|
|
2
|
+
import{a as e}from"./chunk-NASE45GS.js";export{e as defineConfig};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aurios/mizzling",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "A CLI tool for managing Mizzle projects",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"tsup": "^8.5.1",
|
|
52
|
+
"@aurios/mizzle": "1.1.5",
|
|
52
53
|
"@repo/shared": "0.0.3",
|
|
53
|
-
"@repo/typescript-config": "0.0.0",
|
|
54
54
|
"@repo/vitest-config": "0.0.0",
|
|
55
|
-
"@
|
|
55
|
+
"@repo/typescript-config": "0.0.0"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"check": "tsc --noEmit",
|
package/src/config.ts
CHANGED
|
@@ -142,12 +142,21 @@ export function getClient(config: MizzleConfig): DynamoDBClient {
|
|
|
142
142
|
* @returns A promise that resolves to the loaded and overridden configuration.
|
|
143
143
|
* @throws Error if the configuration file is missing or invalid.
|
|
144
144
|
*/
|
|
145
|
-
export async function loadConfig(configName
|
|
145
|
+
export async function loadConfig(configName?: string): Promise<MizzleConfig> {
|
|
146
146
|
const envConfig = process.env.MIZZLE_CONFIG;
|
|
147
|
-
|
|
147
|
+
let configPath = envConfig;
|
|
148
148
|
|
|
149
|
-
if (!
|
|
150
|
-
|
|
149
|
+
if (!configPath) {
|
|
150
|
+
const tsPath = join(process.cwd(), configName || "mizzle.config.ts");
|
|
151
|
+
const jsPath = join(process.cwd(), configName || "mizzle.config.js");
|
|
152
|
+
|
|
153
|
+
if (existsSync(tsPath)) {
|
|
154
|
+
configPath = tsPath;
|
|
155
|
+
} else if (existsSync(jsPath)) {
|
|
156
|
+
configPath = jsPath;
|
|
157
|
+
} else {
|
|
158
|
+
throw new Error(`Could not find ${configName || "mizzle.config.ts/js"} in current directory.`);
|
|
159
|
+
}
|
|
151
160
|
}
|
|
152
161
|
|
|
153
162
|
try {
|
package/dist/chunk-DKDRM5WU.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import{join as s}from"path";import{existsSync as c}from"fs";import{DynamoDBClient as a}from"@aws-sdk/client-dynamodb";import{fromIni as p}from"@aws-sdk/credential-provider-ini";import{NodeHttpHandler as f}from"@smithy/node-http-handler";import l from"http";import m from"https";function v(e){return e}function M(e){let i={keepAlive:!0,maxSockets:1/0},t={region:e.region||"us-east-1",endpoint:e.endpoint,maxAttempts:e.maxAttempts,requestHandler:new f({httpAgent:new l.Agent(i),httpsAgent:new m.Agent(i)})};return e.credentials?t.credentials=e.credentials:e.profile?t.credentials=p({profile:e.profile}):e.endpoint&&(e.endpoint.includes("localhost")||e.endpoint.includes("127.0.0.1"))&&(t.credentials={accessKeyId:"local",secretAccessKey:"local"}),new a(t)}async function h(e="mizzle.config.ts"){let t=process.env.MIZZLE_CONFIG||s(process.cwd(),e);if(!c(t))throw new Error(`Could not find ${e} in current directory.`);try{let n=await import(t),o=n.default||n;if(!o||typeof o!="object")throw new Error("Invalid config: default export must be an object");if(!o.schema)throw new Error("Invalid config: missing 'schema' path");if(!o.out)throw new Error("Invalid config: missing 'out' directory");let r={...o};return process.env.MIZZLE_REGION&&(r.region=process.env.MIZZLE_REGION),process.env.MIZZLE_ENDPOINT&&(r.endpoint=process.env.MIZZLE_ENDPOINT),process.env.MIZZLE_SCHEMA&&(r.schema=process.env.MIZZLE_SCHEMA),process.env.MIZZLE_OUT&&(r.out=process.env.MIZZLE_OUT),process.env.MIZZLE_VERBOSE&&(r.verbose=process.env.MIZZLE_VERBOSE==="true"),process.env.MIZZLE_STRICT&&(r.strict=process.env.MIZZLE_STRICT==="true"),r}catch(n){if(n instanceof Error&&n.message.startsWith("Invalid config"))throw n;let o=n instanceof Error?n.message:String(n);throw new Error(`Failed to load config: ${o}`)}}export{v as a,M as b,h as c};
|