@lunora/seed 1.0.0-alpha.50 → 1.0.0-alpha.52
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/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{createSeedClient-D_7gUsRT.mjs → createSeedClient-dWHSm-Hz.mjs} +1 -1
- package/dist/packem_shared/plan-ByJsHJfZ.mjs +1 -0
- package/dist/packem_shared/{plan.d-SaRxbrrI.d.mts → plan.d-CDkBhI-1.d.mts} +10 -0
- package/dist/packem_shared/{plan.d-SaRxbrrI.d.ts → plan.d-CDkBhI-1.d.ts} +10 -0
- package/dist/packem_shared/seedPlan-BJ6IbsTq.mjs +1 -0
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.mjs +1 -1
- package/package.json +1 -1
- package/dist/packem_shared/plan-kxH2oi4Q.mjs +0 -1
- package/dist/packem_shared/seedPlan-CXA_R7YD.mjs +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from '@lunora/server';
|
|
2
|
-
import { O as OverrideContext } from "./packem_shared/plan.d-
|
|
3
|
-
export { type S as SeedCounts, type a as SeedOptions, type b as SeedOverrides, type T as TablePlan, s as seedPlan } from "./packem_shared/plan.d-
|
|
2
|
+
import { O as OverrideContext } from "./packem_shared/plan.d-CDkBhI-1.mjs";
|
|
3
|
+
export { type S as SeedCounts, type a as SeedOptions, type b as SeedOverrides, type T as TablePlan, s as seedPlan } from "./packem_shared/plan.d-CDkBhI-1.mjs";
|
|
4
4
|
/**
|
|
5
5
|
* A typed, schema-aware seed client — the ergonomic DX layer over {@link seedPlan}.
|
|
6
6
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Schema } from '@lunora/server';
|
|
2
|
-
import { O as OverrideContext } from "./packem_shared/plan.d-
|
|
3
|
-
export { type S as SeedCounts, type a as SeedOptions, type b as SeedOverrides, type T as TablePlan, s as seedPlan } from "./packem_shared/plan.d-
|
|
2
|
+
import { O as OverrideContext } from "./packem_shared/plan.d-CDkBhI-1.js";
|
|
3
|
+
export { type S as SeedCounts, type a as SeedOptions, type b as SeedOverrides, type T as TablePlan, s as seedPlan } from "./packem_shared/plan.d-CDkBhI-1.js";
|
|
4
4
|
/**
|
|
5
5
|
* A typed, schema-aware seed client — the ergonomic DX layer over {@link seedPlan}.
|
|
6
6
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createSeedClient as o}from"./packem_shared/createSeedClient-
|
|
1
|
+
import{createSeedClient as o}from"./packem_shared/createSeedClient-dWHSm-Hz.mjs";import{V as a}from"./packem_shared/plan-ByJsHJfZ.mjs";export{o as createSeedClient,a as seedPlan};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{l as x,
|
|
1
|
+
import{l as x,V as $,k as C}from"./plan-ByJsHJfZ.mjs";const S=t=>Array.isArray(t)&&t.length===2&&typeof t[0]=="number"&&typeof t[1]=="number",A=(t,u,l,s)=>{const n=o=>typeof o=="number"?o:C.int([l,u,"count"],{max:o[1],min:o[0]});return t===void 0?{count:s}:typeof t=="number"?{count:t}:typeof t=="function"?{count:t(n)}:S(t)?{count:n(t)}:{count:t.length,partials:t}},M=(t,u,l)=>{const s={};if(t!==void 0){const n=new Set(t.flatMap(o=>Object.keys(o)));for(const o of n)s[o]=c=>t[c.index-l]?.[o]}for(const[n,o]of Object.entries(u??{}))s[n]=o;return s},R=(t,u={})=>{const{defaultCount:l=10,persist:s,seed:n=0}=u,o={},c={},a={},O=async(e,r,d)=>{x(n);const{count:f,partials:y}=A(r,e,n,l),m=a[e]??0,v=$(t,{counts:{[e]:f},existingIds:c,indexOffset:{[e]:m},only:[e],overrides:{[e]:M(y,d?.overrides,m)},seed:n});let h=[];for(const{rows:p,table:i}of v){const g=p.map(w=>w._id);o[i]??=[],o[i].push(...p),c[i]??=[],c[i].push(...g),a[i]=(a[i]??0)+p.length,i===e&&(h=g),s!==void 0&&await s(i,p)}return{[e]:h}};let b=Promise.resolve();const j=(e,r,d)=>{const f=b.then(()=>O(e,r,d));return b=f.then(()=>{},()=>{}),f},k={$ids:c,$reset:()=>{for(const e of Object.keys(o))delete o[e];for(const e of Object.keys(c))delete c[e];for(const e of Object.keys(a))delete a[e]},$store:o};return new Proxy(k,{get(e,r,d){return typeof r=="string"&&!r.startsWith("$")&&Object.hasOwn(t.tables,r)?(f,y)=>j(r,f,y):Reflect.get(e,r,d)}})};export{R as createSeedClient};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{LunoraError as O}from"@lunora/errors";import{faker as u}from"@faker-js/faker";import{optionalInner as Z}from"@lunora/values";let S=0;const G=(e,t)=>e<t?-1:e>t?1:0,A=e=>e===void 0?"undefined":typeof e=="bigint"?`${e.toString()}n`:e===null||typeof e!="object"?JSON.stringify(e)??"null":Array.isArray(e)?`[${e.map(t=>A(t)).join(",")}]`:`{${Object.keys(e).toSorted(G).map(t=>`${JSON.stringify(t)}:${A(e[t])}`).join(",")}}`,z=(e,t)=>{let n=3735928559^t,r=1103547991^t;for(let a=0;a<e.length;a+=1){const s=e.codePointAt(a)??0;n=Math.imul(n^s,2654435761),r=Math.imul(r^s,1597334677)}return n=Math.imul(n^n>>>16,2246822507),n^=Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507),r^=Math.imul(n^n>>>13,3266489909),4294967296*(2097151&r)+(n>>>0)},H="\0",K=e=>{const t=typeof e=="string"?H+e:A(e);return z(t,S)%4294967296},W=e=>{if(typeof e=="number"){S=e>>>0;return}if(typeof e=="string"){S=z(e,0)%4294967296;return}let t=0;for(const n of e)t=Math.imul(t^n,2654435761)>>>0;S=t},m=(e,t)=>(u.seed(K(e)),t()),C=(e,t)=>{if(typeof t=="number")return t;const[n,r]=t;return m(["__count__",e],()=>u.number.int({max:r,min:n}))},X=e=>e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1),Y=/[a-z]/,ee=/[A-Z]/,te=/\d/,l={bool(e){return m(e,()=>u.datatype.boolean())},char(e){return m(e,()=>u.string.alpha(1))},city(e){return m(e,()=>u.location.city())},country(e){return m(e,()=>u.location.country())},countryCode(e){return m(e,()=>u.location.countryCode())},dateString(e,t){const n=t?.min??new Date("1980-01-01T00:00:00.000Z"),r=t?.max??new Date("2020-01-01T00:00:00.000Z");return m(e,()=>u.date.between({from:n,to:r}).toISOString())},digit(e){return m(e,()=>String(u.number.int({max:9,min:0})))},email(e){return m(e,()=>u.internet.email().toLowerCase())},firstName(e){return m(e,()=>u.person.firstName())},float(e,t){const{fractionDigits:n=2,max:r=1e3,min:a=0}=t??{};return m(e,()=>u.number.float({fractionDigits:n,max:r,min:a}))},fullName(e){return m(e,()=>u.person.fullName())},hex(e){return m(e,()=>u.string.hexadecimal({casing:"lower",length:1,prefix:""}))},int(e,t){const{max:n=1e3,min:r=0}=t??{};return m(e,()=>u.number.int({max:n,min:r}))},ipv4(e){return m(e,()=>u.internet.ipv4())},lastName(e){return m(e,()=>u.person.lastName())},mac(e){return m(e,()=>u.internet.mac())},oneOf(e,t){if(t.length!==0)return m(e,()=>u.helpers.arrayElement(t))},paragraph(e){return m(e,()=>u.lorem.paragraph())},password(e){return m(e,()=>u.internet.password())},phoneNumber(e){return m(e,()=>u.phone.number())},scramble(e,t){const n=new Set(t?.preserve);return Array.from({length:e.length},(r,a)=>{const s=e.charAt(a);return n.has(s)?s:Y.test(s)?m([e,a,"l"],()=>u.string.alpha({casing:"lower",length:1})):ee.test(s)?m([e,a,"u"],()=>u.string.alpha({casing:"upper",length:1})):te.test(s)?m([e,a,"d"],()=>String(u.number.int({max:9,min:0}))):s}).join("")},sentence(e,t){return m(e,()=>u.lorem.sentence(t?{max:t.max??8,min:t.min??3}:void 0))},slug(e){return m(e,()=>u.lorem.slug())},someOf(e,t,n){const r=Math.min(C(["__some__",e],t),n.length);return m(e,()=>u.helpers.arrayElements(n,r))},streetAddress(e){return m(e,()=>u.location.streetAddress())},streetName(e){return m(e,()=>u.location.street())},timezone(e){return m(e,()=>u.location.timeZone())},times(e,t,n){const r=C(e,t),a=[];for(let s=0;s<r;s+=1)a.push(n([e,s]));return a},url(e){return m(e,()=>u.internet.url())},username(e){return m(e,()=>u.internet.username())},uuid(e){return m(e,()=>u.string.uuid())},word(e,t){const n=m(e,()=>u.lorem.word());return t?.capitalize===!0?X(n):n},words(e,t){return m(e,()=>u.lorem.words(t?{max:t.max??5,min:t.min??2}:void 0))}},h=e=>e._meta??{},V=e=>Z(e)??e,U=e=>{const{column:t}=h(e);if(t?.defaultValue!==void 0||t?.defaultFn!==void 0)return!0;const n=Z(e);return n===void 0?!1:U(n)},ne=(e,t)=>{const n=V(t),r=h(n);return{fkTable:n.kind==="id"?r.tableName:void 0,hasServerDefault:U(t),kind:n.kind,name:e,nullable:r.column?.notNull===!1,optional:t.kind==="optional",validator:n}},re=e=>{const{tables:t}=e;return Object.entries(t).map(([n,r])=>({fields:Object.entries(r.shape).map(([a,s])=>ne(a,s)),name:n}))},oe=(e,t)=>{const n=new Map(e.map(o=>[o.name,o])),r=o=>{const d=n.get(o);if(d===void 0)return new Set;const f=new Set;for(const g of d.fields)g.fkTable!==void 0&&g.fkTable!==o&&t.has(g.fkTable)&&f.add(g.fkTable);return f},a=[],s=new Set,i=[...t].filter(o=>n.has(o));for(;i.length>0;){const o=i.findIndex(g=>[...r(g)].every(w=>s.has(w))),d=o===-1?0:o,[f]=i.splice(d,1);if(f===void 0)break;a.push(f),s.add(f)}return a},ae=(e,t,n=new Set)=>{const r=new Map(e.map(i=>[i.name,i])),a=new Set(t),s=[...a];for(;s.length>0;){const i=s.pop();if(i===void 0)break;const o=r.get(i);if(o!==void 0&&!n.has(i))for(const d of o.fields)d.fkTable!==void 0&&d.fkTable!==i&&r.has(d.fkTable)&&!a.has(d.fkTable)&&(a.add(d.fkTable),s.push(d.fkTable))}return a},ie=e=>h(e).constraints??{},se=[{generate:e=>l.email(e),keywords:["email"]},{generate:e=>l.firstName(e),keywords:["firstname"]},{generate:e=>l.lastName(e),keywords:["lastname","surname"]},{generate:e=>l.username(e),keywords:["username"]},{generate:e=>l.fullName(e),keywords:["name"]},{generate:e=>l.sentence(e,{max:5,min:2}),keywords:["title"]},{generate:e=>l.url(e),keywords:["url","link","image","avatar"]},{generate:e=>l.phoneNumber(e),keywords:["phone"]},{generate:e=>l.paragraph(e),keywords:["description","bio","body","content","text"]},{generate:e=>l.slug(e),keywords:["slug","key","code"]},{generate:e=>l.city(e),keywords:["city"]},{generate:e=>l.country(e),keywords:["country"]},{generate:e=>l.streetAddress(e),keywords:["address","street"]},{generate:e=>l.password(e),keywords:["password","secret","token"]}],ue=new Set(["at","date","deadline","expires","expiry","since","timestamp","until"]),le=/([a-z\d])([A-Z])/gu,me=/[\s_-]+/u,de=e=>e.replaceAll(le,"$1 $2").split(me).filter(t=>t!=="").map(t=>t.toLowerCase()),ce=4320*60*60*1e3,fe=e=>{const t=de(e).at(-1);return t!==void 0&&ue.has(t)},ge=(e,t)=>t-l.int(e,{max:ce,min:0}),pe=(e,t,n)=>{const r=e.toLowerCase(),a=se.find(f=>f.keywords.some(g=>r.includes(g))),s=a===void 0?l.word(t):a.generate(t),{maxLength:i,minLength:o}=n;if(i!==void 0&&o!==void 0&&o>i)throw new O("INTERNAL",`Seed constraint error for field "${e}": minLength (${String(o)}) > maxLength (${String(i)}). Adjust the schema constraints.`);const d=i!==void 0&&s.length>i?s.slice(0,i):s;return o!==void 0&&d.length<o?d.padEnd(o,d.length>0?d:"x"):d},y=(e,t,n,r)=>{const a=V(e),s=ie(a);if(s.enum!==void 0&&s.enum.length>0)return l.oneOf(n,s.enum);switch(a.kind){case"any":return l.word(n);case"array":{const i=h(a).inner;return i===void 0?[]:l.times(n,[1,3],o=>y(i,t,o,r))}case"bigint":return l.int(n,{max:1e6,min:0});case"boolean":return l.bool(n);case"bytes":return Array.from({length:8},(i,o)=>l.int([n,o],{max:255,min:0}));case"date":case"timestamp":return new Date(l.dateString(n)).getTime();case"id":return l.uuid(n);case"literal":return h(a).value;case"null":return null;case"number":{const{maximum:i,minimum:o}=s;if(i===void 0&&o===void 0&&fe(t))return ge(n,r);if(i!==void 0&&o!==void 0&&o>i)throw new O("INTERNAL",`Seed constraint error for field "${t}": minimum (${String(o)}) > maximum (${String(i)}). Adjust the schema constraints.`);const d=o??0,f=i??1e3;return!Number.isInteger(d)||!Number.isInteger(f)?l.float(n,{max:f,min:d}):l.int(n,{max:f,min:d})}case"object":{const i=h(a).shape??{};return Object.fromEntries(Object.entries(i).map(([o,d])=>[o,y(d,o,[n,o],r)]))}case"record":{const{keyValidator:i,valueValidator:o}=h(a),d=l.times(n,[1,3],f=>{const g=i===void 0?l.word(["k",f]):String(y(i,t,["k",f],r)),w=o===void 0?l.word(["v",f]):y(o,t,["v",f],r);return[g,w]});return Object.fromEntries(d)}case"storage":return`seed/${l.uuid(n)}`;case"string":return pe(t,n,s);case"union":{const i=h(a).members??[],o=l.oneOf(n,i);return o===void 0?l.word(n):y(o,t,[n,"u"],r)}default:return l.word(n)}},he=(e,t)=>typeof e=="function"?e(t):e,we=(e,t)=>{if(!e.optional)return e.nullable?null:l.uuid(t)},be=(e,t,n,r,a)=>{const s=e.fkTable,i=s===t?(r.get(t)??[]).slice(0,n):r.get(s)??[],o=a[s]??[];return o.length===0?i:[...i,...o]},R=(e,t,n,r)=>[e,t,n,r],ye=(e,t,n,r,a,s,i)=>{if(e.fkTable!==void 0){const o=be(e,t,r,a,s);return o.length===0?we(e,n):l.oneOf(n,o)}if(!e.hasServerDefault)return y(e.validator,e.name,n,i)},Se=(e,t={})=>{const{counts:n={},defaultCount:r=10,existingIds:a={},indexOffset:s={},now:i=Date.now(),only:o,overrides:d={},seed:f=0}=t;W(f);const g=re(e);if(o!==void 0){const c=new Set(g.map(b=>b.name));for(const b of o)if(!c.has(b)){const v=g.map(N=>N.name).join(", ");throw new O("BAD_REQUEST",`unknown table "${b}" in seed \`only\` — schema defines: ${v||"(no tables)"}`)}}const w=new Set(o??g.map(c=>c.name)),F=new Set(Object.keys(a).filter(c=>!w.has(c)&&(a[c]??[]).length>0)),J=new Set([...ae(g,w,F)].filter(c=>w.has(c)||(a[c]??[]).length===0)),P=oe(g,J),Q=new Map(g.map(c=>[c.name,c])),j=new Map,_={},M=[];for(const c of P){const b=Q.get(c);if(b===void 0)continue;const v=d[c]??{},N=n[c]??r,B=s[c]??0,L=[];j.set(c,L);const $=[];_[c]=$;for(let x=0;x<N;x+=1){const T=B+x,k={},E=(p,q)=>{if(Object.hasOwn(v,p)){const I=he(v[p],{field:p,index:T,row:k,store:_,table:c});if(I!==void 0){k[p]=I;return}}const D=q();D!==void 0&&(k[p]=D)};E("_id",()=>l.uuid(R(f,c,T,"_id"))),L.push(k._id);for(const p of b.fields)E(p.name,()=>ye(p,c,R(f,c,T,p.name),x,j,a,i));$.push(k)}M.push({rows:$,table:c})}return M};export{re as S,Se as V,l as k,W as l};
|
|
@@ -52,6 +52,16 @@ interface SeedOptions {
|
|
|
52
52
|
* earlier batch.
|
|
53
53
|
*/
|
|
54
54
|
indexOffset?: Readonly<Record<string, number>>;
|
|
55
|
+
/**
|
|
56
|
+
* Wall-clock reference for time-valued columns (`createdAt`, `expiresAt`, …),
|
|
57
|
+
* as epoch-ms. Defaults to now.
|
|
58
|
+
*
|
|
59
|
+
* Pin it to make a plan byte-for-byte reproducible: seeding is deterministic
|
|
60
|
+
* in `seed` alone for every other column, and this is the one input that
|
|
61
|
+
* would otherwise drift between runs. A pinned `(seed, now)` pair is what
|
|
62
|
+
* makes a seeded screenshot, test fixture, or bug report replayable.
|
|
63
|
+
*/
|
|
64
|
+
now?: number;
|
|
55
65
|
/**
|
|
56
66
|
* Restrict seeding to these tables. Transitive `v.id(...)` parents are added
|
|
57
67
|
* automatically (unless already covered by `existingIds`) so child foreign
|
|
@@ -52,6 +52,16 @@ interface SeedOptions {
|
|
|
52
52
|
* earlier batch.
|
|
53
53
|
*/
|
|
54
54
|
indexOffset?: Readonly<Record<string, number>>;
|
|
55
|
+
/**
|
|
56
|
+
* Wall-clock reference for time-valued columns (`createdAt`, `expiresAt`, …),
|
|
57
|
+
* as epoch-ms. Defaults to now.
|
|
58
|
+
*
|
|
59
|
+
* Pin it to make a plan byte-for-byte reproducible: seeding is deterministic
|
|
60
|
+
* in `seed` alone for every other column, and this is the one input that
|
|
61
|
+
* would otherwise drift between runs. A pinned `(seed, now)` pair is what
|
|
62
|
+
* makes a seeded screenshot, test fixture, or bug report replayable.
|
|
63
|
+
*/
|
|
64
|
+
now?: number;
|
|
55
65
|
/**
|
|
56
66
|
* Restrict seeding to these tables. Transitive `v.id(...)` parents are added
|
|
57
67
|
* automatically (unless already covered by `existingIds`) so child foreign
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"@lunora/errors";import{V as a}from"./plan-ByJsHJfZ.mjs";export{a as seedPlan};
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from '@lunora/server';
|
|
2
2
|
import { TestHarness } from '@lunora/testing';
|
|
3
|
-
import { a as SeedOptions } from "./packem_shared/plan.d-
|
|
3
|
+
import { a as SeedOptions } from "./packem_shared/plan.d-CDkBhI-1.mjs";
|
|
4
4
|
declare const seed: (harness: TestHarness, schema: Schema, options?: SeedOptions) => Promise<Record<string, string[]>>;
|
|
5
5
|
export { seed };
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from '@lunora/server';
|
|
2
2
|
import { TestHarness } from '@lunora/testing';
|
|
3
|
-
import { a as SeedOptions } from "./packem_shared/plan.d-
|
|
3
|
+
import { a as SeedOptions } from "./packem_shared/plan.d-CDkBhI-1.js";
|
|
4
4
|
declare const seed: (harness: TestHarness, schema: Schema, options?: SeedOptions) => Promise<Record<string, string[]>>;
|
|
5
5
|
export { seed };
|
package/dist/testing.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{V as y,S}from"./packem_shared/plan-ByJsHJfZ.mjs";const b=(f,r,a)=>{if(r.size===0&&a.size===0)return f;const n={...f};for(const s of r){const e=n[s];typeof e=="number"&&(n[s]=BigInt(e))}for(const s of a){const e=n[s];Array.isArray(e)&&(n[s]=Uint8Array.from(e).buffer)}return n},z=async(f,r,a={})=>{const n=y(r,a),s=S(r),e=new Map,m=new Map;for(const o of s){const i=new Set(o.fields.filter(t=>t.kind==="bigint").map(t=>t.name)),c=new Set(o.fields.filter(t=>t.kind==="bytes").map(t=>t.name));i.size>0&&e.set(o.name,i),c.size>0&&m.set(o.name,c)}const l={};return await f.run(async o=>{const i=o.db.insert;for(const{rows:c,table:t}of n){const p=[],w=e.get(t)??new Set,u=m.get(t)??new Set;for(const d of c)p.push(await i(t,b(d,w,u),{allowExplicitId:!0}));l[t]=p}}),l};export{z as seed};
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{LunoraError as A}from"@lunora/errors";import{faker as i}from"@faker-js/faker";import{optionalInner as Z}from"@lunora/values";let x=0;const K=(e,n)=>e<n?-1:e>n?1:0,O=e=>e===void 0?"undefined":typeof e=="bigint"?`${e.toString()}n`:e===null||typeof e!="object"?JSON.stringify(e)??"null":Array.isArray(e)?`[${e.map(n=>O(n)).join(",")}]`:`{${Object.keys(e).toSorted(K).map(n=>`${JSON.stringify(n)}:${O(e[n])}`).join(",")}}`,z=(e,n)=>{let t=3735928559^n,r=1103547991^n;for(let s=0;s<e.length;s+=1){const o=e.codePointAt(s)??0;t=Math.imul(t^o,2654435761),r=Math.imul(r^o,1597334677)}return t=Math.imul(t^t>>>16,2246822507),t^=Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507),r^=Math.imul(t^t>>>13,3266489909),4294967296*(2097151&r)+(t>>>0)},q="\0",G=e=>{const n=typeof e=="string"?q+e:O(e);return z(n,x)%4294967296},H=e=>{if(typeof e=="number"){x=e>>>0;return}if(typeof e=="string"){x=z(e,0)%4294967296;return}let n=0;for(const t of e)n=Math.imul(n^t,2654435761)>>>0;x=n},u=(e,n)=>(i.seed(G(e)),n()),C=(e,n)=>{if(typeof n=="number")return n;const[t,r]=n;return u(["__count__",e],()=>i.number.int({max:r,min:t}))},W=e=>e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1),X=/[a-z]/,Y=/[A-Z]/,ee=/\d/,l={bool(e){return u(e,()=>i.datatype.boolean())},char(e){return u(e,()=>i.string.alpha(1))},city(e){return u(e,()=>i.location.city())},country(e){return u(e,()=>i.location.country())},countryCode(e){return u(e,()=>i.location.countryCode())},dateString(e,n){const t=n?.min??new Date("1980-01-01T00:00:00.000Z"),r=n?.max??new Date("2020-01-01T00:00:00.000Z");return u(e,()=>i.date.between({from:t,to:r}).toISOString())},digit(e){return u(e,()=>String(i.number.int({max:9,min:0})))},email(e){return u(e,()=>i.internet.email().toLowerCase())},firstName(e){return u(e,()=>i.person.firstName())},float(e,n){const{fractionDigits:t=2,max:r=1e3,min:s=0}=n??{};return u(e,()=>i.number.float({fractionDigits:t,max:r,min:s}))},fullName(e){return u(e,()=>i.person.fullName())},hex(e){return u(e,()=>i.string.hexadecimal({casing:"lower",length:1,prefix:""}))},int(e,n){const{max:t=1e3,min:r=0}=n??{};return u(e,()=>i.number.int({max:t,min:r}))},ipv4(e){return u(e,()=>i.internet.ipv4())},lastName(e){return u(e,()=>i.person.lastName())},mac(e){return u(e,()=>i.internet.mac())},oneOf(e,n){if(n.length!==0)return u(e,()=>i.helpers.arrayElement(n))},paragraph(e){return u(e,()=>i.lorem.paragraph())},password(e){return u(e,()=>i.internet.password())},phoneNumber(e){return u(e,()=>i.phone.number())},scramble(e,n){const t=new Set(n?.preserve);return Array.from({length:e.length},(r,s)=>{const o=e.charAt(s);return t.has(o)?o:X.test(o)?u([e,s,"l"],()=>i.string.alpha({casing:"lower",length:1})):Y.test(o)?u([e,s,"u"],()=>i.string.alpha({casing:"upper",length:1})):ee.test(o)?u([e,s,"d"],()=>String(i.number.int({max:9,min:0}))):o}).join("")},sentence(e,n){return u(e,()=>i.lorem.sentence(n?{max:n.max??8,min:n.min??3}:void 0))},slug(e){return u(e,()=>i.lorem.slug())},someOf(e,n,t){const r=Math.min(C(["__some__",e],n),t.length);return u(e,()=>i.helpers.arrayElements(t,r))},streetAddress(e){return u(e,()=>i.location.streetAddress())},streetName(e){return u(e,()=>i.location.street())},timezone(e){return u(e,()=>i.location.timeZone())},times(e,n,t){const r=C(e,n),s=[];for(let o=0;o<r;o+=1)s.push(t([e,o]));return s},url(e){return u(e,()=>i.internet.url())},username(e){return u(e,()=>i.internet.username())},uuid(e){return u(e,()=>i.string.uuid())},word(e,n){const t=u(e,()=>i.lorem.word());return n?.capitalize===!0?W(t):t},words(e,n){return u(e,()=>i.lorem.words(n?{max:n.max??5,min:n.min??2}:void 0))}},p=e=>e._meta??{},U=e=>Z(e)??e,V=e=>{const{column:n}=p(e);if(n?.defaultValue!==void 0||n?.defaultFn!==void 0)return!0;const t=Z(e);return t===void 0?!1:V(t)},ne=(e,n)=>{const t=U(n),r=p(t);return{fkTable:t.kind==="id"?r.tableName:void 0,hasServerDefault:V(n),kind:t.kind,name:e,nullable:r.column?.notNull===!1,optional:n.kind==="optional",validator:t}},te=e=>{const{tables:n}=e;return Object.entries(n).map(([t,r])=>({fields:Object.entries(r.shape).map(([s,o])=>ne(s,o)),name:t}))},re=(e,n)=>{const t=new Map(e.map(m=>[m.name,m])),r=m=>{const d=t.get(m);if(d===void 0)return new Set;const f=new Set;for(const g of d.fields)g.fkTable!==void 0&&g.fkTable!==m&&n.has(g.fkTable)&&f.add(g.fkTable);return f},s=[],o=new Set,a=[...n].filter(m=>t.has(m));for(;a.length>0;){const m=a.findIndex(g=>[...r(g)].every(S=>o.has(S))),d=m===-1?0:m,[f]=a.splice(d,1);if(f===void 0)break;s.push(f),o.add(f)}return s},oe=(e,n,t=new Set)=>{const r=new Map(e.map(a=>[a.name,a])),s=new Set(n),o=[...s];for(;o.length>0;){const a=o.pop();if(a===void 0)break;const m=r.get(a);if(m!==void 0&&!t.has(a))for(const d of m.fields)d.fkTable!==void 0&&d.fkTable!==a&&r.has(d.fkTable)&&!s.has(d.fkTable)&&(s.add(d.fkTable),o.push(d.fkTable))}return s},ae=e=>p(e).constraints??{},se=[{generate:e=>l.email(e),keywords:["email"]},{generate:e=>l.firstName(e),keywords:["firstname"]},{generate:e=>l.lastName(e),keywords:["lastname","surname"]},{generate:e=>l.username(e),keywords:["username"]},{generate:e=>l.fullName(e),keywords:["name"]},{generate:e=>l.sentence(e,{max:5,min:2}),keywords:["title"]},{generate:e=>l.url(e),keywords:["url","link","image","avatar"]},{generate:e=>l.phoneNumber(e),keywords:["phone"]},{generate:e=>l.paragraph(e),keywords:["description","bio","body","content","text"]},{generate:e=>l.slug(e),keywords:["slug","key","code"]},{generate:e=>l.city(e),keywords:["city"]},{generate:e=>l.country(e),keywords:["country"]},{generate:e=>l.streetAddress(e),keywords:["address","street"]},{generate:e=>l.password(e),keywords:["password","secret","token"]}],ie=(e,n,t)=>{const r=e.toLowerCase(),s=se.find(f=>f.keywords.some(g=>r.includes(g))),o=s===void 0?l.word(n):s.generate(n),{maxLength:a,minLength:m}=t;if(a!==void 0&&m!==void 0&&m>a)throw new A("INTERNAL",`Seed constraint error for field "${e}": minLength (${String(m)}) > maxLength (${String(a)}). Adjust the schema constraints.`);const d=a!==void 0&&o.length>a?o.slice(0,a):o;return m!==void 0&&d.length<m?d.padEnd(m,d.length>0?d:"x"):d},b=(e,n,t)=>{const r=U(e),s=ae(r);if(s.enum!==void 0&&s.enum.length>0)return l.oneOf(t,s.enum);switch(r.kind){case"any":return l.word(t);case"array":{const o=p(r).inner;return o===void 0?[]:l.times(t,[1,3],a=>b(o,n,a))}case"bigint":return l.int(t,{max:1e6,min:0});case"boolean":return l.bool(t);case"bytes":return Array.from({length:8},(o,a)=>l.int([t,a],{max:255,min:0}));case"date":case"timestamp":return new Date(l.dateString(t)).getTime();case"id":return l.uuid(t);case"literal":return p(r).value;case"null":return null;case"number":{const{maximum:o,minimum:a}=s;if(o!==void 0&&a!==void 0&&a>o)throw new A("INTERNAL",`Seed constraint error for field "${n}": minimum (${String(a)}) > maximum (${String(o)}). Adjust the schema constraints.`);const m=a??0,d=o??1e3;return!Number.isInteger(m)||!Number.isInteger(d)?l.float(t,{max:d,min:m}):l.int(t,{max:d,min:m})}case"object":{const o=p(r).shape??{};return Object.fromEntries(Object.entries(o).map(([a,m])=>[a,b(m,a,[t,a])]))}case"record":{const{keyValidator:o,valueValidator:a}=p(r),m=l.times(t,[1,3],d=>{const f=o===void 0?l.word(["k",d]):String(b(o,n,["k",d])),g=a===void 0?l.word(["v",d]):b(a,n,["v",d]);return[f,g]});return Object.fromEntries(m)}case"storage":return`seed/${l.uuid(t)}`;case"string":return ie(n,t,s);case"union":{const o=p(r).members??[],a=l.oneOf(t,o);return a===void 0?l.word(t):b(a,n,[t,"u"])}default:return l.word(t)}},ue=(e,n)=>typeof e=="function"?e(n):e,le=(e,n)=>{if(!e.optional)return e.nullable?null:l.uuid(n)},me=(e,n,t,r,s)=>{const o=e.fkTable,a=o===n?(r.get(n)??[]).slice(0,t):r.get(o)??[],m=s[o]??[];return m.length===0?a:[...a,...m]},R=(e,n,t,r)=>[e,n,t,r],de=(e,n,t,r,s,o)=>{if(e.fkTable!==void 0){const a=me(e,n,r,s,o);return a.length===0?le(e,t):l.oneOf(t,a)}if(!e.hasServerDefault)return b(e.validator,e.name,t)},he=(e,n={})=>{const{counts:t={},defaultCount:r=10,existingIds:s={},indexOffset:o={},only:a,overrides:m={},seed:d=0}=n;H(d);const f=te(e);if(a!==void 0){const c=new Set(f.map(w=>w.name));for(const w of a)if(!c.has(w)){const k=f.map($=>$.name).join(", ");throw new A("BAD_REQUEST",`unknown table "${w}" in seed \`only\` — schema defines: ${k||"(no tables)"}`)}}const g=new Set(a??f.map(c=>c.name)),S=new Set(Object.keys(s).filter(c=>!g.has(c)&&(s[c]??[]).length>0)),F=new Set([...oe(f,g,S)].filter(c=>g.has(c)||(s[c]??[]).length===0)),J=re(f,F),P=new Map(f.map(c=>[c.name,c])),j=new Map,_={},M=[];for(const c of J){const w=P.get(c);if(w===void 0)continue;const k=m[c]??{},$=t[c]??r,Q=o[c]??0,E=[];j.set(c,E);const N=[];_[c]=N;for(let v=0;v<$;v+=1){const T=Q+v,y={},L=(h,B)=>{if(Object.hasOwn(k,h)){const D=ue(k[h],{field:h,index:T,row:y,store:_,table:c});if(D!==void 0){y[h]=D;return}}const I=B();I!==void 0&&(y[h]=I)};L("_id",()=>l.uuid(R(d,c,T,"_id"))),E.push(y._id);for(const h of w.fields)L(h.name,()=>de(h,c,R(d,c,T,h.name),v,j,s));N.push(y)}M.push({rows:N,table:c})}return M};export{te as S,he as U,l as k,H as l};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"@lunora/errors";import{U as a}from"./plan-kxH2oi4Q.mjs";export{a as seedPlan};
|