@levrbet/shared 0.1.191 → 0.1.192

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.
@@ -2,7 +2,7 @@
2
2
  // Re-export everything from the Prisma client
3
3
  // This allows consumers to import from "@levrbet/shared/core" instead of "@prisma/client"
4
4
  //
5
- // Note: Consumers must run `levrbet-setup-prisma` (postinstall) to generate the Prisma client
5
+ // The Prisma client is automatically generated when @levrbet/shared is installed.
6
6
  // PrismaClient requires Node.js runtime and won't work in browsers.
7
7
  // Browser/React consumers should only use types and enums.
8
8
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/prisma/index.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,0FAA0F;AAC1F,EAAE;AACF,8FAA8F;AAC9F,oEAAoE;AACpE,2DAA2D;;;;;;;;;;;;;;;;AAE3D,iDAA8B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/prisma/index.ts"],"names":[],"mappings":";AAAA,8CAA8C;AAC9C,0FAA0F;AAC1F,EAAE;AACF,kFAAkF;AAClF,oEAAoE;AACpE,2DAA2D;;;;;;;;;;;;;;;;AAE3D,iDAA8B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@levrbet/shared",
3
- "version": "0.1.191",
3
+ "version": "0.1.192",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "exports": {
@@ -39,6 +39,7 @@
39
39
  "dev": "npm run build && npm pack",
40
40
  "clean": "rm -rf dist .tsbuildinfo",
41
41
  "prepublishOnly": "npm run build",
42
+ "postinstall": "node scripts/postinstall.js",
42
43
  "test-get-healthy-indexer": "tsx src/core/indexers/indexers.service.ts"
43
44
  },
44
45
  "peerDependencies": {
@@ -74,7 +75,6 @@
74
75
  "@types/object-hash": "^3.0.6",
75
76
  "@types/react": ">=18.0.0",
76
77
  "cross-fetch": "^4.1.0",
77
- "prisma": "^6.0.0",
78
78
  "react": ">=18.0.0",
79
79
  "tsx": "^4.20.6",
80
80
  "typescript": "^5.9.3"
@@ -113,7 +113,8 @@
113
113
  "typescript-memoize": "^1.1.1",
114
114
  "viem": "2.38.3",
115
115
  "winston": "3.18.3",
116
- "zod": "^4.1.12"
116
+ "zod": "^4.1.12",
117
+ "prisma": "^6.0.0"
117
118
  },
118
119
  "publishConfig": {
119
120
  "access": "public"
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Postinstall script for @levrbet/shared
5
+ * Automatically generates Prisma client using the schema bundled in this package.
6
+ *
7
+ * This runs automatically when consumers install @levrbet/shared.
8
+ * The schema.prisma stays in this package - no files are copied to the consumer.
9
+ */
10
+
11
+ const { execSync } = require("child_process")
12
+ const fs = require("fs")
13
+ const path = require("path")
14
+
15
+ // Find the consumer's project root (walk up from node_modules/@levrbet/shared)
16
+ function findProjectRoot() {
17
+ let dir = __dirname
18
+
19
+ // Walk up to find the project root (where we exit node_modules)
20
+ while (dir !== path.dirname(dir)) {
21
+ const parentDir = path.dirname(dir)
22
+ const parentName = path.basename(parentDir)
23
+
24
+ // If parent is node_modules, go up one more level to get project root
25
+ if (parentName === "node_modules") {
26
+ return path.dirname(parentDir)
27
+ }
28
+
29
+ // If we find a package.json that's not in node_modules, we're at project root
30
+ const packageJsonPath = path.join(dir, "package.json")
31
+ if (fs.existsSync(packageJsonPath)) {
32
+ try {
33
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"))
34
+ // Make sure it's not our own package
35
+ if (pkg.name !== "@levrbet/shared") {
36
+ return dir
37
+ }
38
+ } catch (e) {
39
+ // Ignore parse errors
40
+ }
41
+ }
42
+
43
+ dir = parentDir
44
+ }
45
+
46
+ // Fallback to current working directory
47
+ return process.cwd()
48
+ }
49
+
50
+ // Check if we're in the package itself (development mode) - skip setup
51
+ function isDevMode() {
52
+ const packageDir = path.join(__dirname, "..")
53
+ const ownPackageJson = path.join(packageDir, "package.json")
54
+
55
+ if (fs.existsSync(ownPackageJson)) {
56
+ try {
57
+ const pkg = JSON.parse(fs.readFileSync(ownPackageJson, "utf8"))
58
+ const projectRoot = findProjectRoot()
59
+
60
+ // We're in development if the project root is the package itself
61
+ if (pkg.name === "@levrbet/shared" && projectRoot === packageDir) {
62
+ return true
63
+ }
64
+ } catch (e) {
65
+ // Ignore
66
+ }
67
+ }
68
+ return false
69
+ }
70
+
71
+ // Main execution
72
+ function main() {
73
+ // Skip if in development mode
74
+ if (isDevMode()) {
75
+ console.log("[@levrbet/shared] Skipping postinstall (development mode)")
76
+ return
77
+ }
78
+
79
+ const projectRoot = findProjectRoot()
80
+ const packageDir = path.join(__dirname, "..")
81
+ const schemaPath = path.join(packageDir, "prisma", "schema.prisma")
82
+
83
+ // Verify schema exists
84
+ if (!fs.existsSync(schemaPath)) {
85
+ console.error("[@levrbet/shared] Error: schema.prisma not found at", schemaPath)
86
+ process.exit(1)
87
+ }
88
+
89
+ console.log("[@levrbet/shared] Generating Prisma client...")
90
+ console.log(`[@levrbet/shared] Schema: ${schemaPath}`)
91
+ console.log(`[@levrbet/shared] Project root: ${projectRoot}`)
92
+
93
+ try {
94
+ // Generate Prisma client using the schema from this package
95
+ // Run from the consumer's project root so @prisma/client is found there
96
+ execSync(`npx prisma generate --schema="${schemaPath}"`, {
97
+ stdio: "inherit",
98
+ cwd: projectRoot,
99
+ })
100
+ console.log("[@levrbet/shared] Prisma client generated successfully!")
101
+ } catch (err) {
102
+ console.error("[@levrbet/shared] Failed to generate Prisma client:", err.message)
103
+ console.error(
104
+ "[@levrbet/shared] You may need to run: npx prisma generate --schema=node_modules/@levrbet/shared/prisma/schema.prisma"
105
+ )
106
+ // Don't exit with error - allow install to complete even if generation fails
107
+ // This prevents blocking installs when @prisma/client isn't yet installed
108
+ }
109
+ }
110
+
111
+ main()
@@ -1,98 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  /**
4
- * This script sets up Prisma for consumers of @levrbet/shared.
5
- * It copies the schema.prisma file and generates the Prisma client.
4
+ * Manual Prisma setup for @levrbet/shared.
6
5
  *
7
- * Runs automatically on postinstall, or manually via: npx levrbet-prisma-setup
6
+ * NOTE: This is now just a fallback. Prisma client is automatically generated
7
+ * when you install @levrbet/shared via the postinstall script.
8
+ *
9
+ * Run this manually if the automatic setup didn't work:
10
+ * npx levrbet-prisma-setup
8
11
  */
9
- console.log("\nšŸš€ Starting Prisma setup for @levrbet/shared...\n")
10
- const { execSync } = require("child_process")
11
- const fs = require("fs")
12
- const path = require("path")
13
-
14
- // Find the consumer's project root (walk up from node_modules/@levrbet/shared)
15
- function findProjectRoot() {
16
- let dir = __dirname
17
-
18
- // Walk up to find the project root (where we exit node_modules)
19
- while (dir !== path.dirname(dir)) {
20
- const parentDir = path.dirname(dir)
21
- const parentName = path.basename(parentDir)
22
-
23
- // If parent is node_modules, go up one more level to get project root
24
- if (parentName === "node_modules") {
25
- return path.dirname(parentDir)
26
- }
27
-
28
- // If we find a package.json that's not in node_modules, we're at project root
29
- const packageJsonPath = path.join(dir, "package.json")
30
- if (fs.existsSync(packageJsonPath)) {
31
- try {
32
- const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"))
33
- // Make sure it's not our own package
34
- if (pkg.name !== "@levrbet/shared") {
35
- return dir
36
- }
37
- } catch (e) {
38
- // Ignore parse errors
39
- }
40
- }
41
-
42
- dir = parentDir
43
- }
44
-
45
- // Fallback to current working directory
46
- return process.cwd()
47
- }
48
-
49
- const projectRoot = findProjectRoot()
50
- const schemaSource = path.join(__dirname, "..", "prisma", "schema.prisma")
51
- const prismaDir = path.join(projectRoot, "prisma")
52
- const schemaDest = path.join(prismaDir, "schema.prisma")
53
-
54
- // Check if we're in the package itself (development mode) - skip setup
55
- const ownPackageJson = path.join(__dirname, "..", "package.json")
56
- if (fs.existsSync(ownPackageJson)) {
57
- try {
58
- const pkg = JSON.parse(fs.readFileSync(ownPackageJson, "utf8"))
59
- if (pkg.name === "@levrbet/shared" && projectRoot === path.join(__dirname, "..")) {
60
- // We're in the package itself during development, skip consumer setup
61
- console.log("ā„¹ļø Skipping consumer setup (running in @levrbet/shared development mode)")
62
- process.exit(0)
63
- }
64
- } catch (e) {
65
- // Ignore
66
- }
67
- }
68
-
69
- console.log("šŸ”§ Setting up Prisma for @levrbet/shared...")
70
- console.log(` Project root: ${projectRoot}\n`)
71
-
72
- // Create prisma directory if it doesn't exist
73
- if (!fs.existsSync(prismaDir)) {
74
- fs.mkdirSync(prismaDir, { recursive: true })
75
- console.log("āœ… Created prisma/ directory")
76
- }
77
-
78
- // Copy schema.prisma
79
- try {
80
- fs.copyFileSync(schemaSource, schemaDest)
81
- console.log("āœ… Copied schema.prisma to prisma/schema.prisma")
82
- } catch (err) {
83
- console.error("āŒ Failed to copy schema.prisma:", err.message)
84
- process.exit(1)
85
- }
86
-
87
- // Generate Prisma client
88
- console.log("\nšŸ”„ Generating Prisma client...")
89
- try {
90
- execSync("npx prisma generate", { stdio: "inherit", cwd: projectRoot })
91
- console.log("\nāœ… Prisma client generated successfully!")
92
- } catch (err) {
93
- console.error("\nāŒ Failed to generate Prisma client:", err.message)
94
- process.exit(1)
95
- }
96
12
 
97
- console.log("\nšŸŽ‰ Prisma setup complete!")
98
- console.log("\nMake sure to set the MONGO_URI environment variable in your .env file.")
13
+ require("./postinstall.js")