@lunora/seed 0.0.0 → 1.0.0-alpha.2
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 +105 -0
- package/README.md +170 -9
- package/__assets__/package-og.svg +14 -0
- package/dist/index.d.mts +64 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.mjs +2 -0
- package/dist/packem_shared/createSeedClient-CI9LRLTi.mjs +92 -0
- package/dist/packem_shared/plan-DirmkctQ.mjs +497 -0
- package/dist/packem_shared/plan.d-BQ6LiWIk.d.mts +78 -0
- package/dist/packem_shared/plan.d-BQ6LiWIk.d.ts +78 -0
- package/dist/packem_shared/seedPlan-CDSmSgjY.mjs +1 -0
- package/dist/testing.d.mts +5 -0
- package/dist/testing.d.ts +5 -0
- package/dist/testing.mjs +53 -0
- package/package.json +45 -14
package/dist/testing.mjs
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { s as seedPlan, i as introspectSchema } from './packem_shared/plan-DirmkctQ.mjs';
|
|
2
|
+
|
|
3
|
+
const reviveRow = (row, bigintFields, bytesFields) => {
|
|
4
|
+
if (bigintFields.size === 0 && bytesFields.size === 0) {
|
|
5
|
+
return row;
|
|
6
|
+
}
|
|
7
|
+
const revived = { ...row };
|
|
8
|
+
for (const field of bigintFields) {
|
|
9
|
+
const value = revived[field];
|
|
10
|
+
if (typeof value === "number") {
|
|
11
|
+
revived[field] = BigInt(value);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
for (const field of bytesFields) {
|
|
15
|
+
const value = revived[field];
|
|
16
|
+
if (Array.isArray(value)) {
|
|
17
|
+
revived[field] = Uint8Array.from(value).buffer;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return revived;
|
|
21
|
+
};
|
|
22
|
+
const seed = async (harness, schema, options = {}) => {
|
|
23
|
+
const plan = seedPlan(schema, options);
|
|
24
|
+
const specs = introspectSchema(schema);
|
|
25
|
+
const bigintFieldsByTable = /* @__PURE__ */ new Map();
|
|
26
|
+
const bytesFieldsByTable = /* @__PURE__ */ new Map();
|
|
27
|
+
for (const spec of specs) {
|
|
28
|
+
const bigintFields = new Set(spec.fields.filter((field) => field.kind === "bigint").map((field) => field.name));
|
|
29
|
+
const bytesFields = new Set(spec.fields.filter((field) => field.kind === "bytes").map((field) => field.name));
|
|
30
|
+
if (bigintFields.size > 0) {
|
|
31
|
+
bigintFieldsByTable.set(spec.name, bigintFields);
|
|
32
|
+
}
|
|
33
|
+
if (bytesFields.size > 0) {
|
|
34
|
+
bytesFieldsByTable.set(spec.name, bytesFields);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const ids = {};
|
|
38
|
+
await harness.run(async (context) => {
|
|
39
|
+
const insert = context.db.insert;
|
|
40
|
+
for (const { rows, table } of plan) {
|
|
41
|
+
const tableIds = [];
|
|
42
|
+
const bigintFields = bigintFieldsByTable.get(table) ?? /* @__PURE__ */ new Set();
|
|
43
|
+
const bytesFields = bytesFieldsByTable.get(table) ?? /* @__PURE__ */ new Set();
|
|
44
|
+
for (const row of rows) {
|
|
45
|
+
tableIds.push(await insert(table, reviveRow(row, bigintFields, bytesFields), { allowExplicitId: true }));
|
|
46
|
+
}
|
|
47
|
+
ids[table] = tableIds;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return ids;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export { seed };
|
package/package.json
CHANGED
|
@@ -1,28 +1,59 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/seed",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "1.0.0-alpha.2",
|
|
4
4
|
"description": "Schema-driven, deterministic database seeding for Lunora: realistic fake data from defineSchema",
|
|
5
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cloudflare",
|
|
7
|
+
"faker",
|
|
8
|
+
"fixtures",
|
|
9
|
+
"lunora",
|
|
10
|
+
"seed"
|
|
11
|
+
],
|
|
6
12
|
"homepage": "https://lunora.sh",
|
|
13
|
+
"bugs": "https://github.com/anolilab/lunora/issues",
|
|
14
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Daniel Bannert",
|
|
17
|
+
"email": "d.bannert@anolilab.de"
|
|
18
|
+
},
|
|
7
19
|
"repository": {
|
|
8
20
|
"type": "git",
|
|
9
21
|
"url": "git+https://github.com/anolilab/lunora.git",
|
|
10
22
|
"directory": "packages/seed"
|
|
11
23
|
},
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"cloudflare",
|
|
18
|
-
"seed",
|
|
19
|
-
"faker",
|
|
20
|
-
"fixtures"
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE.md",
|
|
28
|
+
"__assets__"
|
|
21
29
|
],
|
|
30
|
+
"type": "module",
|
|
31
|
+
"sideEffects": false,
|
|
32
|
+
"main": "./dist/index.mjs",
|
|
33
|
+
"module": "./dist/index.mjs",
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"exports": {
|
|
36
|
+
".": {
|
|
37
|
+
"types": "./dist/index.d.ts",
|
|
38
|
+
"import": "./dist/index.mjs"
|
|
39
|
+
},
|
|
40
|
+
"./testing": {
|
|
41
|
+
"types": "./dist/testing.d.ts",
|
|
42
|
+
"import": "./dist/testing.mjs"
|
|
43
|
+
},
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
},
|
|
22
46
|
"publishConfig": {
|
|
23
47
|
"access": "public"
|
|
24
48
|
},
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@faker-js/faker": "^10.5.0"
|
|
51
|
+
},
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"@lunora/server": "1.0.0-alpha.2",
|
|
54
|
+
"@lunora/values": "1.0.0-alpha.1"
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": "^22.15.0 || >=24.11.0"
|
|
58
|
+
}
|
|
28
59
|
}
|