@lunora/seed 0.0.0 → 1.0.0-alpha.1

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/LICENSE.md ADDED
@@ -0,0 +1,105 @@
1
+ # Functional Source License, Version 1.1, Apache 2.0 Future License
2
+
3
+ ## Abbreviation
4
+
5
+ FSL-1.1-Apache-2.0
6
+
7
+ ## Notice
8
+
9
+ Copyright 2026 anolilab and contributors
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or service
34
+ that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software that
39
+ exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee using
52
+ the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to the
59
+ infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, EVEN
79
+ IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following will
93
+ apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
package/README.md CHANGED
@@ -1,18 +1,179 @@
1
- # @lunora/seed
1
+ <!-- START_PACKAGE_OG_IMAGE_PLACEHOLDER -->
2
2
 
3
- > ⚠️ **Placeholder release.** This package name is reserved for the [Lunora](https://lunora.sh) framework. The real `1.0.0-alpha` release is coming soon.
3
+ <a href="https://www.anolilab.com/open-source" align="center">
4
4
 
5
- Schema-driven, deterministic database seeding for Lunora: realistic fake data from defineSchema
5
+ <img src="__assets__/package-og.svg" alt="seed" />
6
6
 
7
- Lunora is a type-safe, real-time backend framework for Cloudflare Workers + Durable Objects with a Vite-first developer experience.
7
+ </a>
8
8
 
9
- - Website: https://lunora.sh
10
- - Repository: https://github.com/anolilab/lunora
9
+ <h3 align="center">Schema-driven, deterministic database seeding for Lunora: realistic fake data from defineSchema</h3>
11
10
 
12
- ## Status
11
+ <!-- END_PACKAGE_OG_IMAGE_PLACEHOLDER -->
13
12
 
14
- This is a `0.0.0` placeholder to reserve the npm name. Do not depend on it yet — APIs and exports are not published in this version. Watch the repository for the alpha release.
13
+ <br />
14
+
15
+ <div align="center">
16
+
17
+ [![typescript-image][typescript-badge]][typescript-url]
18
+ [![FSL-1.1-Apache-2.0 licence][license-badge]][license]
19
+ [![npm version][npm-version-badge]][npm-version]
20
+ [![npm downloads][npm-downloads-badge]][npm-downloads]
21
+ [![PRs Welcome][prs-welcome-badge]][prs-welcome]
22
+
23
+ </div>
24
+
25
+ ---
26
+
27
+ <div align="center">
28
+ <p>
29
+ <sup>
30
+ Daniel Bannert's open source work is supported by the community on <a href="https://github.com/sponsors/prisis">GitHub Sponsors</a>
31
+ </sup>
32
+ </p>
33
+ </div>
34
+
35
+ ---
36
+
37
+ `@lunora/seed` populates a Lunora database with realistic, production-like fake data derived from your `defineSchema`. It introspects every table, maps each field to a generator (field-name aware — a `string` column called `email` becomes an email address, `firstName` a first name, and so on), resolves foreign keys by inserting parent tables before their children, and lets you override any value.
38
+
39
+ Generation is **deterministic**: it is built on a vendored, input-hashed generator (a rebuilt [`copycat`](https://github.com/supabase-community/copycat)) layered over [`@faker-js/faker`](https://fakerjs.dev). The same `seed` value and schema always produce the same rows, so fixtures are reproducible across runs and machines.
40
+
41
+ Part of the [Lunora](https://github.com/anolilab/lunora) framework — a type-safe, real-time backend on Cloudflare Workers + Durable Objects with a Vite-first DX.
42
+
43
+ ## Install
44
+
45
+ ```sh
46
+ npm install @lunora/seed
47
+ ```
48
+
49
+ ```sh
50
+ yarn add @lunora/seed
51
+ ```
52
+
53
+ ```sh
54
+ pnpm add @lunora/seed
55
+ ```
56
+
57
+ ## Usage
58
+
59
+ ### Generate a plan
60
+
61
+ ```ts
62
+ import { seedPlan } from "@lunora/seed";
63
+ import schema from "./lunora/schema";
64
+
65
+ const plan = seedPlan(schema, {
66
+ counts: { users: 10, posts: 30 },
67
+ seed: 1,
68
+ overrides: {
69
+ users: { email: (ctx) => `user${ctx.index}@example.com` },
70
+ },
71
+ });
72
+
73
+ // plan === [{ table: "users", rows: [...] }, { table: "posts", rows: [...] }]
74
+ // (parents before children; every post.authorId points at a generated user)
75
+ ```
76
+
77
+ ### Seed an in-memory test harness
78
+
79
+ ```ts
80
+ import { lunoraTest } from "@lunora/testing";
81
+ import { seed } from "@lunora/seed/testing";
82
+ import schema from "./lunora/schema";
83
+
84
+ const harness = lunoraTest(schema);
85
+ const ids = await seed(harness, schema, { counts: { users: 5, posts: 20 } });
86
+ // ids.users / ids.posts — the inserted document ids, for assertions
87
+ ```
88
+
89
+ ### Typed client
90
+
91
+ For a Snaplet-style, one-table-at-a-time DX, `createSeedClient` exposes each table as a method. Foreign keys connect to whatever was seeded earlier in the run, FK parents are pulled in automatically, and state accumulates on `$store`/`$ids` (clear it with `$reset()`):
92
+
93
+ ```ts
94
+ import { createSeedClient } from "@lunora/seed";
95
+ import schema from "./lunora/schema";
96
+
97
+ const seed = createSeedClient(schema, { seed: 1 });
98
+
99
+ const { users } = await seed.users(5);
100
+ const { posts } = await seed.posts((x) => x([10, 20])); // a deterministic count in [10, 20]
101
+
102
+ // Explicit partial rows — omitted columns are still generated:
103
+ await seed.users([{ name: "Alice" }, { email: "bob@example.com", name: "Bob" }]);
104
+
105
+ seed.$ids.users; // every user id generated this run
106
+ ```
107
+
108
+ Pass your generated `InsertModel` type — `createSeedClient<InsertModel>(schema)` — for autocomplete on each table's columns. Or skip the wiring: when `@lunora/seed` is a declared dependency, codegen emits `_generated/seed.ts` with the schema and `InsertModel` already bound.
109
+
110
+ ```ts
111
+ import { createSeedClient } from "@/lunora/_generated/seed";
112
+
113
+ const seed = createSeedClient({ seed: 1 });
114
+ const { users } = await seed.users(5); // columns typed from InsertModel
115
+ ```
116
+
117
+ Supply a `persist` hook (`SeedClientOptions.persist`) to write each batch as it is generated (parents first); the client is pure when it is omitted. Per-call field overrides go in the second argument: `seed.posts(3, { overrides: { title: (ctx) => `Post ${ctx.index}` } })`.
118
+
119
+ ### Seed a running dev worker
120
+
121
+ ```bash
122
+ lunora seed --count 25 # 25 rows per table (default 10)
123
+ lunora seed --table posts --count 100 # one table (FK parents seeded automatically)
124
+ lunora seed --seed 42 # reproducible run
125
+ lunora seed --reset # wipe local .wrangler/state first (local dev only)
126
+ lunora seed --dry-run # print NDJSON, write nothing
127
+ ```
128
+
129
+ Also: `--batch-size` (rows per HTTP request, default 500), `--url` (worker URL, default `http://localhost:8787`), `--prod` (requires an explicit `--url`), `--token` / `LUNORA_ADMIN_TOKEN` (admin bearer; prefer the env var), `--yes` (skip the non-local confirmation prompt). `--reset` is local-only and cannot be combined with `--prod` or a remote `--url`.
130
+
131
+ ## Limitations
132
+
133
+ - **`.unique()` columns are not enforced.** Each value is hashed independently, so a unique column over a small value space (a bounded integer, a boolean, a short enum) can collide across rows. Strings such as emails and uuids are effectively unique in practice. Colliding rows are rejected by the import path rather than silently overwritten.
134
+ - **Seeding is deterministic by design.** Re-running with the same `--seed` regenerates identical `_id`s, which the import path skips as conflicts. Use a different `--seed` for fresh rows, or `--reset` to wipe local state first.
135
+
136
+ > This README covers the basics. For the full API, options, and guides, see the **[documentation](https://lunora.sh/docs/packages/seed)**.
137
+
138
+ ## Related
139
+
140
+ - [`@lunora/server`](https://www.npmjs.com/package/@lunora/server) — defines the `defineSchema` that seeding introspects.
141
+ - [`@lunora/testing`](https://www.npmjs.com/package/@lunora/testing) — the in-memory harness `@lunora/seed/testing` seeds.
142
+ - [`@lunora/cli`](https://www.npmjs.com/package/@lunora/cli) — ships the `lunora seed` command.
143
+
144
+ ## Supported Node.js Versions
145
+
146
+ Libraries in this ecosystem make the best effort to track [Node.js' release schedule](https://github.com/nodejs/release#release-schedule).
147
+ Here's [a post on why we think this is important](https://medium.com/the-node-js-collection/maintainers-should-consider-following-node-js-release-schedule-ab08ed4de71a).
148
+
149
+ ## Contributing
150
+
151
+ If you would like to help take a look at the [list of issues](https://github.com/anolilab/lunora/issues) and check our [Contributing](https://github.com/anolilab/lunora/blob/alpha/.github/CONTRIBUTING.md) guidelines.
152
+
153
+ > **Note:** please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
154
+
155
+ ## Credits
156
+
157
+ - [Daniel Bannert](https://github.com/prisis)
158
+ - [All Contributors](https://github.com/anolilab/lunora/graphs/contributors)
159
+
160
+ ## Made with ❤️ at Anolilab
161
+
162
+ This is an open source project and will always remain free to use. If you think it's cool, please star it 🌟. [Anolilab](https://www.anolilab.com/open-source) is a Development and AI Studio. Contact us at [hello@anolilab.com](mailto:hello@anolilab.com) if you need any help with these technologies or just want to say hi!
15
163
 
16
164
  ## License
17
165
 
18
- FSL-1.1-Apache-2.0
166
+ The Lunora seed package is open-sourced software licensed under the [FSL-1.1-Apache-2.0][license].
167
+
168
+ <!-- badges -->
169
+
170
+ [license-badge]: https://img.shields.io/badge/license-FSL--1.1--Apache--2.0-blue.svg?style=for-the-badge
171
+ [license]: https://github.com/anolilab/lunora/blob/alpha/LICENSE.md
172
+ [npm-version-badge]: https://img.shields.io/npm/v/@lunora/seed?style=for-the-badge
173
+ [npm-version]: https://www.npmjs.com/package/@lunora/seed
174
+ [npm-downloads-badge]: https://img.shields.io/npm/dm/@lunora/seed?style=for-the-badge
175
+ [npm-downloads]: https://www.npmjs.com/package/@lunora/seed
176
+ [prs-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=for-the-badge
177
+ [prs-welcome]: https://github.com/anolilab/lunora/blob/alpha/.github/CONTRIBUTING.md
178
+ [typescript-badge]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
179
+ [typescript-url]: https://www.typescriptlang.org/