@lunora/seed 1.0.0-alpha.26 → 1.0.0-alpha.28
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 +28 -28
- package/dist/index.d.ts +28 -28
- package/dist/packem_shared/plan.d-SaRxbrrI.d.mts +78 -0
- package/dist/packem_shared/plan.d-SaRxbrrI.d.ts +78 -0
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/package.json +2 -2
- package/dist/packem_shared/plan.d-BQ6LiWIk.d.mts +0 -78
- package/dist/packem_shared/plan.d-BQ6LiWIk.d.ts +0 -78
package/dist/index.d.mts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
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-SaRxbrrI.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-SaRxbrrI.mjs";
|
|
4
4
|
/**
|
|
5
|
-
* A typed, schema-aware seed client — the ergonomic DX layer over {@link seedPlan}.
|
|
6
|
-
*
|
|
7
|
-
* Where `seedPlan` generates every table at once, the client lets you author one
|
|
8
|
-
* table at a time, with autocomplete on each table's columns and live foreign-key
|
|
9
|
-
* connection to whatever was seeded earlier this run. Pass your generated
|
|
10
|
-
* `InsertModel` type as the type argument — or let `lunora/_generated/seed.ts`
|
|
11
|
-
* do that for you — for full type inference on each table's columns.
|
|
12
|
-
*
|
|
13
|
-
* The client is deterministic (same `seed` ⇒ same rows and ids) and pure unless a
|
|
14
|
-
* `persist` hook is supplied, in which case each generated batch is also written
|
|
15
|
-
* through it (the test harness, an admin import, …). Because every row carries an
|
|
16
|
-
* explicit `_id`, the returned ids are known whether or not anything is persisted.
|
|
17
|
-
*/
|
|
5
|
+
* A typed, schema-aware seed client — the ergonomic DX layer over {@link seedPlan}.
|
|
6
|
+
*
|
|
7
|
+
* Where `seedPlan` generates every table at once, the client lets you author one
|
|
8
|
+
* table at a time, with autocomplete on each table's columns and live foreign-key
|
|
9
|
+
* connection to whatever was seeded earlier this run. Pass your generated
|
|
10
|
+
* `InsertModel` type as the type argument — or let `lunora/_generated/seed.ts`
|
|
11
|
+
* do that for you — for full type inference on each table's columns.
|
|
12
|
+
*
|
|
13
|
+
* The client is deterministic (same `seed` ⇒ same rows and ids) and pure unless a
|
|
14
|
+
* `persist` hook is supplied, in which case each generated batch is also written
|
|
15
|
+
* through it (the test harness, an admin import, …). Because every row carries an
|
|
16
|
+
* explicit `_id`, the returned ids are known whether or not anything is persisted.
|
|
17
|
+
*/
|
|
18
18
|
/** Picks a concrete count: a fixed number, or a deterministic value within `[min, max]`. */
|
|
19
19
|
type CountHelper = (countOrRange: number | readonly [number, number]) => number;
|
|
20
20
|
/** The per-call population spec: a count, an inclusive range, explicit partial rows, or a count callback. */
|
|
@@ -23,10 +23,10 @@ type SeedSpec<Row> = number | ReadonlyArray<Partial<Row>> | readonly [number, nu
|
|
|
23
23
|
type FieldOverride<Value> = ((context: OverrideContext) => Value) | Value;
|
|
24
24
|
/** Options for a single table call. `overrides` win over any explicit partial rows. */
|
|
25
25
|
interface SeedCallOptions<Row> {
|
|
26
|
-
overrides?: { [K in keyof Row]?: FieldOverride<Row[K]
|
|
26
|
+
overrides?: { [K in keyof Row]?: FieldOverride<Row[K]>; };
|
|
27
27
|
}
|
|
28
28
|
/** The id columns the client emits, keyed by table — the result of a single table call. */
|
|
29
|
-
type SeedCallResult<InsertModel, Table extends keyof InsertModel> = { [K in Table]: string[] };
|
|
29
|
+
type SeedCallResult<InsertModel, Table extends keyof InsertModel> = { [K in Table]: string[]; };
|
|
30
30
|
/** The seeder function exposed for one table. */
|
|
31
31
|
type TableSeeder<InsertModel, Table extends keyof InsertModel> = (spec?: SeedSpec<InsertModel[Table]>, options?: SeedCallOptions<InsertModel[Table]>) => Promise<SeedCallResult<InsertModel, Table>>;
|
|
32
32
|
/** The `$`-prefixed run state shared by every client. */
|
|
@@ -39,7 +39,7 @@ interface SeedClientState {
|
|
|
39
39
|
readonly $store: Readonly<Record<string, ReadonlyArray<Record<string, unknown>>>>;
|
|
40
40
|
}
|
|
41
41
|
/** The per-table seeder methods plus the `$`-prefixed run state. */
|
|
42
|
-
type SeedClient<InsertModel> = SeedClientState & { [Table in keyof InsertModel]: TableSeeder<InsertModel, Table
|
|
42
|
+
type SeedClient<InsertModel> = SeedClientState & { [Table in keyof InsertModel]: TableSeeder<InsertModel, Table>; };
|
|
43
43
|
/** Options for {@link createSeedClient}. */
|
|
44
44
|
interface SeedClientOptions {
|
|
45
45
|
/** Default row count when a table call passes no spec (default `10`). */
|
|
@@ -50,15 +50,15 @@ interface SeedClientOptions {
|
|
|
50
50
|
seed?: number;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
* Create a typed seed client for `schema`. Each table is a method; call it with a
|
|
54
|
-
* count, a range, or explicit partial rows, and its foreign keys connect to rows
|
|
55
|
-
* seeded earlier this run. State accumulates on `$store`/`$ids` and clears with
|
|
56
|
-
* `$reset()`.
|
|
57
|
-
* @example
|
|
58
|
-
* const seed = createSeedClient<InsertModel>(schema, { seed: 1 });
|
|
59
|
-
* const { users } = await seed.users(5);
|
|
60
|
-
* const { posts } = await seed.posts((x) => x([10, 20]));
|
|
61
|
-
* // posts.authorId values are drawn from `users`.
|
|
62
|
-
*/
|
|
53
|
+
* Create a typed seed client for `schema`. Each table is a method; call it with a
|
|
54
|
+
* count, a range, or explicit partial rows, and its foreign keys connect to rows
|
|
55
|
+
* seeded earlier this run. State accumulates on `$store`/`$ids` and clears with
|
|
56
|
+
* `$reset()`.
|
|
57
|
+
* @example
|
|
58
|
+
* const seed = createSeedClient<InsertModel>(schema, { seed: 1 });
|
|
59
|
+
* const { users } = await seed.users(5);
|
|
60
|
+
* const { posts } = await seed.posts((x) => x([10, 20]));
|
|
61
|
+
* // posts.authorId values are drawn from `users`.
|
|
62
|
+
*/
|
|
63
63
|
declare const createSeedClient: <InsertModel = Record<string, Record<string, unknown>>>(schema: Schema, options?: SeedClientOptions) => SeedClient<InsertModel>;
|
|
64
64
|
export { type CountHelper, type OverrideContext, type SeedCallOptions, type SeedCallResult, type SeedClient, type SeedClientOptions, type SeedSpec, createSeedClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
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-SaRxbrrI.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-SaRxbrrI.js";
|
|
4
4
|
/**
|
|
5
|
-
* A typed, schema-aware seed client — the ergonomic DX layer over {@link seedPlan}.
|
|
6
|
-
*
|
|
7
|
-
* Where `seedPlan` generates every table at once, the client lets you author one
|
|
8
|
-
* table at a time, with autocomplete on each table's columns and live foreign-key
|
|
9
|
-
* connection to whatever was seeded earlier this run. Pass your generated
|
|
10
|
-
* `InsertModel` type as the type argument — or let `lunora/_generated/seed.ts`
|
|
11
|
-
* do that for you — for full type inference on each table's columns.
|
|
12
|
-
*
|
|
13
|
-
* The client is deterministic (same `seed` ⇒ same rows and ids) and pure unless a
|
|
14
|
-
* `persist` hook is supplied, in which case each generated batch is also written
|
|
15
|
-
* through it (the test harness, an admin import, …). Because every row carries an
|
|
16
|
-
* explicit `_id`, the returned ids are known whether or not anything is persisted.
|
|
17
|
-
*/
|
|
5
|
+
* A typed, schema-aware seed client — the ergonomic DX layer over {@link seedPlan}.
|
|
6
|
+
*
|
|
7
|
+
* Where `seedPlan` generates every table at once, the client lets you author one
|
|
8
|
+
* table at a time, with autocomplete on each table's columns and live foreign-key
|
|
9
|
+
* connection to whatever was seeded earlier this run. Pass your generated
|
|
10
|
+
* `InsertModel` type as the type argument — or let `lunora/_generated/seed.ts`
|
|
11
|
+
* do that for you — for full type inference on each table's columns.
|
|
12
|
+
*
|
|
13
|
+
* The client is deterministic (same `seed` ⇒ same rows and ids) and pure unless a
|
|
14
|
+
* `persist` hook is supplied, in which case each generated batch is also written
|
|
15
|
+
* through it (the test harness, an admin import, …). Because every row carries an
|
|
16
|
+
* explicit `_id`, the returned ids are known whether or not anything is persisted.
|
|
17
|
+
*/
|
|
18
18
|
/** Picks a concrete count: a fixed number, or a deterministic value within `[min, max]`. */
|
|
19
19
|
type CountHelper = (countOrRange: number | readonly [number, number]) => number;
|
|
20
20
|
/** The per-call population spec: a count, an inclusive range, explicit partial rows, or a count callback. */
|
|
@@ -23,10 +23,10 @@ type SeedSpec<Row> = number | ReadonlyArray<Partial<Row>> | readonly [number, nu
|
|
|
23
23
|
type FieldOverride<Value> = ((context: OverrideContext) => Value) | Value;
|
|
24
24
|
/** Options for a single table call. `overrides` win over any explicit partial rows. */
|
|
25
25
|
interface SeedCallOptions<Row> {
|
|
26
|
-
overrides?: { [K in keyof Row]?: FieldOverride<Row[K]
|
|
26
|
+
overrides?: { [K in keyof Row]?: FieldOverride<Row[K]>; };
|
|
27
27
|
}
|
|
28
28
|
/** The id columns the client emits, keyed by table — the result of a single table call. */
|
|
29
|
-
type SeedCallResult<InsertModel, Table extends keyof InsertModel> = { [K in Table]: string[] };
|
|
29
|
+
type SeedCallResult<InsertModel, Table extends keyof InsertModel> = { [K in Table]: string[]; };
|
|
30
30
|
/** The seeder function exposed for one table. */
|
|
31
31
|
type TableSeeder<InsertModel, Table extends keyof InsertModel> = (spec?: SeedSpec<InsertModel[Table]>, options?: SeedCallOptions<InsertModel[Table]>) => Promise<SeedCallResult<InsertModel, Table>>;
|
|
32
32
|
/** The `$`-prefixed run state shared by every client. */
|
|
@@ -39,7 +39,7 @@ interface SeedClientState {
|
|
|
39
39
|
readonly $store: Readonly<Record<string, ReadonlyArray<Record<string, unknown>>>>;
|
|
40
40
|
}
|
|
41
41
|
/** The per-table seeder methods plus the `$`-prefixed run state. */
|
|
42
|
-
type SeedClient<InsertModel> = SeedClientState & { [Table in keyof InsertModel]: TableSeeder<InsertModel, Table
|
|
42
|
+
type SeedClient<InsertModel> = SeedClientState & { [Table in keyof InsertModel]: TableSeeder<InsertModel, Table>; };
|
|
43
43
|
/** Options for {@link createSeedClient}. */
|
|
44
44
|
interface SeedClientOptions {
|
|
45
45
|
/** Default row count when a table call passes no spec (default `10`). */
|
|
@@ -50,15 +50,15 @@ interface SeedClientOptions {
|
|
|
50
50
|
seed?: number;
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
* Create a typed seed client for `schema`. Each table is a method; call it with a
|
|
54
|
-
* count, a range, or explicit partial rows, and its foreign keys connect to rows
|
|
55
|
-
* seeded earlier this run. State accumulates on `$store`/`$ids` and clears with
|
|
56
|
-
* `$reset()`.
|
|
57
|
-
* @example
|
|
58
|
-
* const seed = createSeedClient<InsertModel>(schema, { seed: 1 });
|
|
59
|
-
* const { users } = await seed.users(5);
|
|
60
|
-
* const { posts } = await seed.posts((x) => x([10, 20]));
|
|
61
|
-
* // posts.authorId values are drawn from `users`.
|
|
62
|
-
*/
|
|
53
|
+
* Create a typed seed client for `schema`. Each table is a method; call it with a
|
|
54
|
+
* count, a range, or explicit partial rows, and its foreign keys connect to rows
|
|
55
|
+
* seeded earlier this run. State accumulates on `$store`/`$ids` and clears with
|
|
56
|
+
* `$reset()`.
|
|
57
|
+
* @example
|
|
58
|
+
* const seed = createSeedClient<InsertModel>(schema, { seed: 1 });
|
|
59
|
+
* const { users } = await seed.users(5);
|
|
60
|
+
* const { posts } = await seed.posts((x) => x([10, 20]));
|
|
61
|
+
* // posts.authorId values are drawn from `users`.
|
|
62
|
+
*/
|
|
63
63
|
declare const createSeedClient: <InsertModel = Record<string, Record<string, unknown>>>(schema: Schema, options?: SeedClientOptions) => SeedClient<InsertModel>;
|
|
64
64
|
export { type CountHelper, type OverrideContext, type SeedCallOptions, type SeedCallResult, type SeedClient, type SeedClientOptions, type SeedSpec, createSeedClient };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Schema } from '@lunora/server';
|
|
2
|
+
/**
|
|
3
|
+
* The pure, I/O-free core of seeding. {@link seedPlan} introspects a schema,
|
|
4
|
+
* generates rows table-by-table in foreign-key order, and resolves every
|
|
5
|
+
* `v.id("parent")` column to a real id of an already-generated parent row. The
|
|
6
|
+
* result feeds every adapter (test harness, CLI, studio) — none of them
|
|
7
|
+
* re-implement generation.
|
|
8
|
+
*
|
|
9
|
+
* Determinism: a `seed` value selects the global copycat mapping, and each value
|
|
10
|
+
* is hashed from `[seed, table, index, field]`, so the same `(schema, options)`
|
|
11
|
+
* always yields byte-identical rows.
|
|
12
|
+
*/
|
|
13
|
+
/** A row context handed to an override function. */
|
|
14
|
+
interface OverrideContext {
|
|
15
|
+
field: string;
|
|
16
|
+
/** The row's absolute index (the `indexOffset` base plus its position in this batch). */
|
|
17
|
+
index: number;
|
|
18
|
+
/** The row built so far (system `_id` first, then earlier fields). */
|
|
19
|
+
row: Record<string, unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* A live, read-only view of every table's rows generated so far this run,
|
|
22
|
+
* keyed by table name. Lets an override correlate across tables (e.g. copy a
|
|
23
|
+
* field from the parent row a foreign key points at). Rows for the current
|
|
24
|
+
* table accumulate as they are built, so only earlier rows are visible.
|
|
25
|
+
*/
|
|
26
|
+
store: Readonly<Record<string, ReadonlyArray<Record<string, unknown>>>>;
|
|
27
|
+
table: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Per-table, per-field overrides. Each override is a static value or a function
|
|
31
|
+
* of the row context; field `_id` overrides the generated primary key.
|
|
32
|
+
*/
|
|
33
|
+
type SeedOverrides = Record<string, Record<string, unknown>>;
|
|
34
|
+
/** Per-table row counts. */
|
|
35
|
+
type SeedCounts = Record<string, number>;
|
|
36
|
+
interface SeedOptions {
|
|
37
|
+
/** Rows per table; falls back to {@link SeedOptions.defaultCount} when a table is absent. */
|
|
38
|
+
counts?: SeedCounts;
|
|
39
|
+
/** Count used for any selected table not present in `counts` (default `10`). */
|
|
40
|
+
defaultCount?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Ids of rows that already exist in the target store, keyed by table. Foreign
|
|
43
|
+
* keys may resolve to these in addition to freshly-seeded parents, and a
|
|
44
|
+
* parent table fully covered here is not re-seeded when it is only pulled in
|
|
45
|
+
* as an FK dependency (it is when named explicitly in `only`).
|
|
46
|
+
*/
|
|
47
|
+
existingIds?: Readonly<Record<string, ReadonlyArray<string>>>;
|
|
48
|
+
/**
|
|
49
|
+
* Per-table absolute index base for generation. Defaults to `0`. A client
|
|
50
|
+
* seeding the same table across several calls passes the running total so
|
|
51
|
+
* each batch hashes from fresh indices and never collides ids with an
|
|
52
|
+
* earlier batch.
|
|
53
|
+
*/
|
|
54
|
+
indexOffset?: Readonly<Record<string, number>>;
|
|
55
|
+
/**
|
|
56
|
+
* Restrict seeding to these tables. Transitive `v.id(...)` parents are added
|
|
57
|
+
* automatically (unless already covered by `existingIds`) so child foreign
|
|
58
|
+
* keys resolve to real rows. The result is still ordered by FK dependency.
|
|
59
|
+
* Default: all tables.
|
|
60
|
+
*/
|
|
61
|
+
only?: ReadonlyArray<string>;
|
|
62
|
+
/** Static values or functions overriding generated columns. */
|
|
63
|
+
overrides?: SeedOverrides;
|
|
64
|
+
/** Deterministic mapping selector — same seed ⇒ same rows. Default `0`. */
|
|
65
|
+
seed?: number;
|
|
66
|
+
}
|
|
67
|
+
/** One table's generated rows, in insert order. Each row carries an explicit `_id`. */
|
|
68
|
+
interface TablePlan {
|
|
69
|
+
rows: ReadonlyArray<Record<string, unknown>>;
|
|
70
|
+
table: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Build a deterministic, FK-consistent set of rows for `schema`.
|
|
74
|
+
* @returns one {@link TablePlan} per seeded table, ordered so a table's FK
|
|
75
|
+
* parents come before it.
|
|
76
|
+
*/
|
|
77
|
+
declare const seedPlan: (schema: Schema, options?: SeedOptions) => ReadonlyArray<TablePlan>;
|
|
78
|
+
export { OverrideContext as O, SeedCounts as S, TablePlan as T, SeedOptions as a, SeedOverrides as b, seedPlan as s };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Schema } from '@lunora/server';
|
|
2
|
+
/**
|
|
3
|
+
* The pure, I/O-free core of seeding. {@link seedPlan} introspects a schema,
|
|
4
|
+
* generates rows table-by-table in foreign-key order, and resolves every
|
|
5
|
+
* `v.id("parent")` column to a real id of an already-generated parent row. The
|
|
6
|
+
* result feeds every adapter (test harness, CLI, studio) — none of them
|
|
7
|
+
* re-implement generation.
|
|
8
|
+
*
|
|
9
|
+
* Determinism: a `seed` value selects the global copycat mapping, and each value
|
|
10
|
+
* is hashed from `[seed, table, index, field]`, so the same `(schema, options)`
|
|
11
|
+
* always yields byte-identical rows.
|
|
12
|
+
*/
|
|
13
|
+
/** A row context handed to an override function. */
|
|
14
|
+
interface OverrideContext {
|
|
15
|
+
field: string;
|
|
16
|
+
/** The row's absolute index (the `indexOffset` base plus its position in this batch). */
|
|
17
|
+
index: number;
|
|
18
|
+
/** The row built so far (system `_id` first, then earlier fields). */
|
|
19
|
+
row: Record<string, unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* A live, read-only view of every table's rows generated so far this run,
|
|
22
|
+
* keyed by table name. Lets an override correlate across tables (e.g. copy a
|
|
23
|
+
* field from the parent row a foreign key points at). Rows for the current
|
|
24
|
+
* table accumulate as they are built, so only earlier rows are visible.
|
|
25
|
+
*/
|
|
26
|
+
store: Readonly<Record<string, ReadonlyArray<Record<string, unknown>>>>;
|
|
27
|
+
table: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Per-table, per-field overrides. Each override is a static value or a function
|
|
31
|
+
* of the row context; field `_id` overrides the generated primary key.
|
|
32
|
+
*/
|
|
33
|
+
type SeedOverrides = Record<string, Record<string, unknown>>;
|
|
34
|
+
/** Per-table row counts. */
|
|
35
|
+
type SeedCounts = Record<string, number>;
|
|
36
|
+
interface SeedOptions {
|
|
37
|
+
/** Rows per table; falls back to {@link SeedOptions.defaultCount} when a table is absent. */
|
|
38
|
+
counts?: SeedCounts;
|
|
39
|
+
/** Count used for any selected table not present in `counts` (default `10`). */
|
|
40
|
+
defaultCount?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Ids of rows that already exist in the target store, keyed by table. Foreign
|
|
43
|
+
* keys may resolve to these in addition to freshly-seeded parents, and a
|
|
44
|
+
* parent table fully covered here is not re-seeded when it is only pulled in
|
|
45
|
+
* as an FK dependency (it is when named explicitly in `only`).
|
|
46
|
+
*/
|
|
47
|
+
existingIds?: Readonly<Record<string, ReadonlyArray<string>>>;
|
|
48
|
+
/**
|
|
49
|
+
* Per-table absolute index base for generation. Defaults to `0`. A client
|
|
50
|
+
* seeding the same table across several calls passes the running total so
|
|
51
|
+
* each batch hashes from fresh indices and never collides ids with an
|
|
52
|
+
* earlier batch.
|
|
53
|
+
*/
|
|
54
|
+
indexOffset?: Readonly<Record<string, number>>;
|
|
55
|
+
/**
|
|
56
|
+
* Restrict seeding to these tables. Transitive `v.id(...)` parents are added
|
|
57
|
+
* automatically (unless already covered by `existingIds`) so child foreign
|
|
58
|
+
* keys resolve to real rows. The result is still ordered by FK dependency.
|
|
59
|
+
* Default: all tables.
|
|
60
|
+
*/
|
|
61
|
+
only?: ReadonlyArray<string>;
|
|
62
|
+
/** Static values or functions overriding generated columns. */
|
|
63
|
+
overrides?: SeedOverrides;
|
|
64
|
+
/** Deterministic mapping selector — same seed ⇒ same rows. Default `0`. */
|
|
65
|
+
seed?: number;
|
|
66
|
+
}
|
|
67
|
+
/** One table's generated rows, in insert order. Each row carries an explicit `_id`. */
|
|
68
|
+
interface TablePlan {
|
|
69
|
+
rows: ReadonlyArray<Record<string, unknown>>;
|
|
70
|
+
table: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Build a deterministic, FK-consistent set of rows for `schema`.
|
|
74
|
+
* @returns one {@link TablePlan} per seeded table, ordered so a table's FK
|
|
75
|
+
* parents come before it.
|
|
76
|
+
*/
|
|
77
|
+
declare const seedPlan: (schema: Schema, options?: SeedOptions) => ReadonlyArray<TablePlan>;
|
|
78
|
+
export { OverrideContext as O, SeedCounts as S, TablePlan as T, SeedOptions as a, SeedOverrides as b, seedPlan as s };
|
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-SaRxbrrI.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-SaRxbrrI.js";
|
|
4
4
|
declare const seed: (harness: TestHarness, schema: Schema, options?: SeedOptions) => Promise<Record<string, string[]>>;
|
|
5
5
|
export { seed };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/seed",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.28",
|
|
4
4
|
"description": "Schema-driven, deterministic database seeding for Lunora: realistic fake data from defineSchema",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@faker-js/faker": "^10.5.0",
|
|
51
|
-
"@lunora/errors": "1.0.0-alpha.
|
|
51
|
+
"@lunora/errors": "1.0.0-alpha.6"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@lunora/server": ">=1.0.0-alpha.24 <2.0.0-0",
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Schema } from '@lunora/server';
|
|
2
|
-
/**
|
|
3
|
-
* The pure, I/O-free core of seeding. {@link seedPlan} introspects a schema,
|
|
4
|
-
* generates rows table-by-table in foreign-key order, and resolves every
|
|
5
|
-
* `v.id("parent")` column to a real id of an already-generated parent row. The
|
|
6
|
-
* result feeds every adapter (test harness, CLI, studio) — none of them
|
|
7
|
-
* re-implement generation.
|
|
8
|
-
*
|
|
9
|
-
* Determinism: a `seed` value selects the global copycat mapping, and each value
|
|
10
|
-
* is hashed from `[seed, table, index, field]`, so the same `(schema, options)`
|
|
11
|
-
* always yields byte-identical rows.
|
|
12
|
-
*/
|
|
13
|
-
/** A row context handed to an override function. */
|
|
14
|
-
interface OverrideContext {
|
|
15
|
-
field: string;
|
|
16
|
-
/** The row's absolute index (the `indexOffset` base plus its position in this batch). */
|
|
17
|
-
index: number;
|
|
18
|
-
/** The row built so far (system `_id` first, then earlier fields). */
|
|
19
|
-
row: Record<string, unknown>;
|
|
20
|
-
/**
|
|
21
|
-
* A live, read-only view of every table's rows generated so far this run,
|
|
22
|
-
* keyed by table name. Lets an override correlate across tables (e.g. copy a
|
|
23
|
-
* field from the parent row a foreign key points at). Rows for the current
|
|
24
|
-
* table accumulate as they are built, so only earlier rows are visible.
|
|
25
|
-
*/
|
|
26
|
-
store: Readonly<Record<string, ReadonlyArray<Record<string, unknown>>>>;
|
|
27
|
-
table: string;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Per-table, per-field overrides. Each override is a static value or a function
|
|
31
|
-
* of the row context; field `_id` overrides the generated primary key.
|
|
32
|
-
*/
|
|
33
|
-
type SeedOverrides = Record<string, Record<string, unknown>>;
|
|
34
|
-
/** Per-table row counts. */
|
|
35
|
-
type SeedCounts = Record<string, number>;
|
|
36
|
-
interface SeedOptions {
|
|
37
|
-
/** Rows per table; falls back to {@link SeedOptions.defaultCount} when a table is absent. */
|
|
38
|
-
counts?: SeedCounts;
|
|
39
|
-
/** Count used for any selected table not present in `counts` (default `10`). */
|
|
40
|
-
defaultCount?: number;
|
|
41
|
-
/**
|
|
42
|
-
* Ids of rows that already exist in the target store, keyed by table. Foreign
|
|
43
|
-
* keys may resolve to these in addition to freshly-seeded parents, and a
|
|
44
|
-
* parent table fully covered here is not re-seeded when it is only pulled in
|
|
45
|
-
* as an FK dependency (it is when named explicitly in `only`).
|
|
46
|
-
*/
|
|
47
|
-
existingIds?: Readonly<Record<string, ReadonlyArray<string>>>;
|
|
48
|
-
/**
|
|
49
|
-
* Per-table absolute index base for generation. Defaults to `0`. A client
|
|
50
|
-
* seeding the same table across several calls passes the running total so
|
|
51
|
-
* each batch hashes from fresh indices and never collides ids with an
|
|
52
|
-
* earlier batch.
|
|
53
|
-
*/
|
|
54
|
-
indexOffset?: Readonly<Record<string, number>>;
|
|
55
|
-
/**
|
|
56
|
-
* Restrict seeding to these tables. Transitive `v.id(...)` parents are added
|
|
57
|
-
* automatically (unless already covered by `existingIds`) so child foreign
|
|
58
|
-
* keys resolve to real rows. The result is still ordered by FK dependency.
|
|
59
|
-
* Default: all tables.
|
|
60
|
-
*/
|
|
61
|
-
only?: ReadonlyArray<string>;
|
|
62
|
-
/** Static values or functions overriding generated columns. */
|
|
63
|
-
overrides?: SeedOverrides;
|
|
64
|
-
/** Deterministic mapping selector — same seed ⇒ same rows. Default `0`. */
|
|
65
|
-
seed?: number;
|
|
66
|
-
}
|
|
67
|
-
/** One table's generated rows, in insert order. Each row carries an explicit `_id`. */
|
|
68
|
-
interface TablePlan {
|
|
69
|
-
rows: ReadonlyArray<Record<string, unknown>>;
|
|
70
|
-
table: string;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Build a deterministic, FK-consistent set of rows for `schema`.
|
|
74
|
-
* @returns one {@link TablePlan} per seeded table, ordered so a table's FK
|
|
75
|
-
* parents come before it.
|
|
76
|
-
*/
|
|
77
|
-
declare const seedPlan: (schema: Schema, options?: SeedOptions) => ReadonlyArray<TablePlan>;
|
|
78
|
-
export { OverrideContext as O, SeedCounts as S, TablePlan as T, SeedOptions as a, SeedOverrides as b, seedPlan as s };
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Schema } from '@lunora/server';
|
|
2
|
-
/**
|
|
3
|
-
* The pure, I/O-free core of seeding. {@link seedPlan} introspects a schema,
|
|
4
|
-
* generates rows table-by-table in foreign-key order, and resolves every
|
|
5
|
-
* `v.id("parent")` column to a real id of an already-generated parent row. The
|
|
6
|
-
* result feeds every adapter (test harness, CLI, studio) — none of them
|
|
7
|
-
* re-implement generation.
|
|
8
|
-
*
|
|
9
|
-
* Determinism: a `seed` value selects the global copycat mapping, and each value
|
|
10
|
-
* is hashed from `[seed, table, index, field]`, so the same `(schema, options)`
|
|
11
|
-
* always yields byte-identical rows.
|
|
12
|
-
*/
|
|
13
|
-
/** A row context handed to an override function. */
|
|
14
|
-
interface OverrideContext {
|
|
15
|
-
field: string;
|
|
16
|
-
/** The row's absolute index (the `indexOffset` base plus its position in this batch). */
|
|
17
|
-
index: number;
|
|
18
|
-
/** The row built so far (system `_id` first, then earlier fields). */
|
|
19
|
-
row: Record<string, unknown>;
|
|
20
|
-
/**
|
|
21
|
-
* A live, read-only view of every table's rows generated so far this run,
|
|
22
|
-
* keyed by table name. Lets an override correlate across tables (e.g. copy a
|
|
23
|
-
* field from the parent row a foreign key points at). Rows for the current
|
|
24
|
-
* table accumulate as they are built, so only earlier rows are visible.
|
|
25
|
-
*/
|
|
26
|
-
store: Readonly<Record<string, ReadonlyArray<Record<string, unknown>>>>;
|
|
27
|
-
table: string;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Per-table, per-field overrides. Each override is a static value or a function
|
|
31
|
-
* of the row context; field `_id` overrides the generated primary key.
|
|
32
|
-
*/
|
|
33
|
-
type SeedOverrides = Record<string, Record<string, unknown>>;
|
|
34
|
-
/** Per-table row counts. */
|
|
35
|
-
type SeedCounts = Record<string, number>;
|
|
36
|
-
interface SeedOptions {
|
|
37
|
-
/** Rows per table; falls back to {@link SeedOptions.defaultCount} when a table is absent. */
|
|
38
|
-
counts?: SeedCounts;
|
|
39
|
-
/** Count used for any selected table not present in `counts` (default `10`). */
|
|
40
|
-
defaultCount?: number;
|
|
41
|
-
/**
|
|
42
|
-
* Ids of rows that already exist in the target store, keyed by table. Foreign
|
|
43
|
-
* keys may resolve to these in addition to freshly-seeded parents, and a
|
|
44
|
-
* parent table fully covered here is not re-seeded when it is only pulled in
|
|
45
|
-
* as an FK dependency (it is when named explicitly in `only`).
|
|
46
|
-
*/
|
|
47
|
-
existingIds?: Readonly<Record<string, ReadonlyArray<string>>>;
|
|
48
|
-
/**
|
|
49
|
-
* Per-table absolute index base for generation. Defaults to `0`. A client
|
|
50
|
-
* seeding the same table across several calls passes the running total so
|
|
51
|
-
* each batch hashes from fresh indices and never collides ids with an
|
|
52
|
-
* earlier batch.
|
|
53
|
-
*/
|
|
54
|
-
indexOffset?: Readonly<Record<string, number>>;
|
|
55
|
-
/**
|
|
56
|
-
* Restrict seeding to these tables. Transitive `v.id(...)` parents are added
|
|
57
|
-
* automatically (unless already covered by `existingIds`) so child foreign
|
|
58
|
-
* keys resolve to real rows. The result is still ordered by FK dependency.
|
|
59
|
-
* Default: all tables.
|
|
60
|
-
*/
|
|
61
|
-
only?: ReadonlyArray<string>;
|
|
62
|
-
/** Static values or functions overriding generated columns. */
|
|
63
|
-
overrides?: SeedOverrides;
|
|
64
|
-
/** Deterministic mapping selector — same seed ⇒ same rows. Default `0`. */
|
|
65
|
-
seed?: number;
|
|
66
|
-
}
|
|
67
|
-
/** One table's generated rows, in insert order. Each row carries an explicit `_id`. */
|
|
68
|
-
interface TablePlan {
|
|
69
|
-
rows: ReadonlyArray<Record<string, unknown>>;
|
|
70
|
-
table: string;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Build a deterministic, FK-consistent set of rows for `schema`.
|
|
74
|
-
* @returns one {@link TablePlan} per seeded table, ordered so a table's FK
|
|
75
|
-
* parents come before it.
|
|
76
|
-
*/
|
|
77
|
-
declare const seedPlan: (schema: Schema, options?: SeedOptions) => ReadonlyArray<TablePlan>;
|
|
78
|
-
export { OverrideContext as O, SeedCounts as S, TablePlan as T, SeedOptions as a, SeedOverrides as b, seedPlan as s };
|