تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
توفّر لك Firebase Data Connect محاكيًا محليًا لإنشاء نماذج أولية شاملة، بالإضافة إلى مسارات التكامل المستمر والتسليم المستمر (CI/CD):
يتفاعل محاكي Data Connect مع نسخة محلية مدمجة من قاعدة بيانات PGLite تتيح لك إنشاء نماذج أولية لطلبات البحث وعمليات التعديل واختبار رمز العميل في بيئة محلية بالكامل.
يمكن أيضًا استخدام محاكي Data Connect في العمل غير التفاعلي. تتيح لك هذه الأداة إجراء اختبارات مبرمَجة، وهي مناسبة للاستخدام مع سير عمل CI/CD. يكون هذا مفيدًا عندما تكون المخططات ثابتة وتريد إنشاء نموذج أولي واختبار الرمز البرمجي من جهة العميل.
يغطّي هذا الدليل عملية تثبيت المحاكي واستخدامه بتفصيل أكبر من دليل البدء السريع.
تثبيت محاكي Data Connect
قبل تثبيت Local Emulator Suite لاستخدام محاكي Data Connect، ستحتاج إلى ما يلي:
الإصدار 18.0 من Node.js أو إصدار أحدث
تثبيت واجهة سطر الأوامر Firebase وإعداد دليل المشروع
ثبِّت واجهة سطر الأوامر Firebase باتّباع دليل التثبيت.
احرص على التحديث بانتظام، لأنّ
Data Connect المحاكي يخضع لعملية تطوير نشطة تتضمّن إصلاح الأخطاء
وإضافة ميزات جديدة.
إذا لم يسبق لك إجراء ذلك، عليك تهيئة دليل العمل الحالي كمشروع على Firebase، وذلك باتّباع التعليمات لتحديد المنتجات التي تريد استخدامها:
firebaseinit
ضبط إعدادات Local Emulator Suite أو تعديلها
إذا بدأت محاكي Data Connect من إضافة Firebase VS Code، سيتم تثبيت المحاكي نيابةً عنك، إذا لزم الأمر.
يمكنك استخدام واجهة سطر الأوامر Firebase لتثبيت المحاكي يدويًا مع
المكوّنات الأخرى المحدّدة في Local Emulator Suite. يبدأ هذا الأمر معالج الإعداد الذي يتيح لك اختيار المحاكيات التي تهمّك وتنزيل ملفات ثنائية خاصة بالمحاكي وتحديد منافذ المحاكي إذا لم تكن الإعدادات التلقائية مناسبة.
firebaseinitemulators
بعد تثبيت المحاكي، لن يتم إجراء أي عمليات تحقّق من التحديثات ولن يتم تنزيل أي ملفات إضافية تلقائيًا إلى أن تحدِّث Firebase إصدار واجهة سطر الأوامر.
اختيار مشروع على Firebase
في عملية الإعداد، يطلب منك Firebase CLI اختيار مشروع Firebase أو إنشائه. إذا اخترت مشروعًا حاليًا سبق أن أعددته باستخدام
Data Connect في وحدة تحكّم Firebase، سيتم اقتراح الإعدادات التي اخترتها
هناك.
إعداد المحاكي
ضبط المحاكي
سيساعدك تنفيذ عملية firebase init في التعرّف على خيارات إعداد المحاكي.
كما هو الحال مع المحاكيات الأخرى في Local Emulator Suite، يتم تخزين معلَمات الإعداد في ملفات المشروع المحلية.
يحتوي ملف firebase.json على عمليات تعيين منافذ المحاكي.
لا ينطبق مفتاح emulators:ui على المحاكي Data Connect.
الاستعانة بمراجع Data Connect محلية وعلنية
إذا أردت التأكّد من عدم التأثير في موارد الإنتاج، اضبط demo-projectID
أو تأكَّد من إعداد رمز العميل للاتصال بالمحاكي، كما هو موضّح في قسم لاحق.
بدء تشغيل المحاكي
إذا كنت تشغّل المحاكي بشكل غير تفاعلي، مثلاً في مهام سير عمل CI/CD، ابدأ تشغيله باستخدام الخيار exec.
firebaseemulators:exec./path/to/test-script.sh
إذا كنت تدمج طلبات بحث وتعديلات محدّدة مسبقًا في رمز العميل وتستخدم المحاكي تحديدًا لاختبار العملاء، يمكنك استخدام الخيار start للعمل التفاعلي. يمكنك أيضًا بدء المحاكي من إضافة VS Code.
firebaseemulators:start
تعديل رمز العميل للتواصل مع المحاكي
اضبط إعداداتك داخل التطبيق أو فئات الاختبار للتفاعل مع
Data Connect المحاكي على النحو التالي.
JavaScript
import{initializeApp}from"firebase/app";import{connectorConfig}from"@name-of-package";import{connectDataConnectEmulator,getDataConnect}from'firebase/data-connect';// TODO: Replace the following with your app's Firebase project configurationconstfirebaseConfig={//...};constapp=initializeApp(firebaseConfig);constdataConnect=getDataConnect(app,connectorConfig);connectDataConnectEmulator(dataConnect,"localhost",9399);// Make calls from your app
Kotlin Android
valconnector=MoviesConnector.instance// Connect to the emulator on "10.0.2.2:9399"connector.dataConnect.useEmulator()// (Alternatively) if you're running your emulator on non-default port:connector.dataConnect.useEmulator(port=9999)// Make calls from your app
iOS
let connector = DataConnect.dataConnect(DefaultConnectorClient.connectorConfig)
// Connect to the emulator on "127.0.0.1:9399"
connector.useEmulator()
// (alternatively) if you're running your emulator on non-default port:
connector.useEmulator(port: 9999)
// Make calls from your app
استخدام المحاكي للاختبار والدمج المستمر
تشغيل صور Local Emulator Suite المحفوظة في حاويات
تتسم عملية تثبيت Local Emulator Suite وإعداده باستخدام الحاويات
في عملية إعداد نموذجية للتكامل المستمر بالبساطة.
في ما يلي بعض المشاكل التي يجب أخذها في الاعتبار:
يتم تثبيت ملفات المحاكي الثنائية وتخزينها مؤقتًا في ~/.cache/firebase/emulators/. يمكنك إضافة هذا المسار إلى إعدادات ذاكرة التخزين المؤقت الخاصة بعملية الدمج المتواصل لتجنُّب عمليات التنزيل المتكرّرة.
إذا لم يكن لديك ملف firebase.json في المستودع، عليك إضافة وسيطة سطر أوامر إلى الأمر emulators:start أو emulators:exec لتحديد المحاكيات التي يجب بدء تشغيلها. على سبيل المثال،
--only dataconnect.
محو قاعدة البيانات بين الاختبارات
لإعادة ضبط بيئات الاختبار بين عمليات التشغيل، تنصح Firebase بما يلي:
كتابة عمليات تغيير مخصّصة للتعامل مع ما يلي:
في عملية الإعداد، املأ نسخة من قاعدة البيانات المحلية بالبيانات الأولية.
في عملية الإيقاف، احذف البيانات المعدَّلة من مثيل قاعدة البيانات بعد الاختبار.
أوجه الاختلاف بين المحاكي Data Connect وبيئة الإنتاج
يحاكي المحاكي Data Connect العديد من ميزات المنتج من جهة الخادم. ومع ذلك، هناك بعض الاستثناءات التي يجب الانتباه إليها:
قد يختلف إصدار PGLite وإعداداته التفصيلية عن إصدار مثيل Cloud SQL المخصّص للإنتاج.
إذا كنت تستخدم المحاكي للتطوير باستخدام Data Connect's
pgvector وعملية الدمج مع Vertex API، يتم إجراء طلبات إلى Cloud Vertex API
مباشرةً، وليس من خلال عملية الدمج مع Vertex في Cloud SQL. ومع ذلك، سيتم إجراء طلبات إلى واجهة برمجة التطبيقات المخصّصة للإنتاج، ما يعني أنّه عليك استخدام مشروع Firebase حقيقي، ولا يمكنك استخدام مشروع demo-، وسيتم تحصيل تكاليف واجهة Vertex API.
تاريخ التعديل الأخير: 2025-09-06 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-09-06 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["\u003cbr /\u003e\n\nFirebase Data Connect provides you with a local emulator for end-to-end\nprototyping as well as continuous integration and continuous deployment\n(CI/CD) flows:\n\n- The Data Connect emulator interacts with a local integrated PGLite database instance to let you prototype queries and mutations and test client code in a fully local environment.\n- The Data Connect emulator can also be used for non-interactive work. It lets you run automated tests and is suitable for use with CI/CD workflows. This is useful when your schemas are stable and you want to prototype and test client-side code.\n\nThis guide covers installation and usage of the emulator in more detail than\nthe quickstart.\n\nInstall the Data Connect emulator\n\nBefore installing the Local Emulator Suite to use the Data Connect\nemulator, you will need:\n\n- Node.js version 18.0 or higher.\n\nInstall the Firebase CLI and set up project directory **Note:** If you've followed the [Get started with Firebase Data Connect](/docs/data-connect/quickstart) guide, you can skip this section.\n\n1. Install the Firebase CLI, [following the installation guide](/docs/cli).\n Be sure to [update regularly](/docs/cli#update-cli), since the\n Data Connect emulator is under active development with bug fixes and\n new features.\n\n2. If you haven't already done so, initialize the current working directory as\n a Firebase project, following prompts to specify which products to use:\n\n firebase init\n\nSet or modify the Local Emulator Suite configuration\n\nIf you started the Data Connect emulator from the Firebase VS Code\nextension, the emulator was installed for you, if needed.\n\nYou can use the Firebase CLI to manually install the emulator along with\nother selected components of the Local Emulator Suite. This command starts a\nconfiguration wizard that lets you select emulators of interest, download the\ncorresponding emulator binary files, and set emulator ports if the defaults are\nnot appropriate. \n\n firebase init emulators\n\nOnce an emulator is installed, no update checks are performed and no additional\nautomatic downloads will occur until you update your Firebase CLI version.\n\nChoose a Firebase project\n\nIn the setup flow, the Firebase CLI prompts you to choose or create a\nFirebase project. If you choose an existing project you've set up with\nData Connect in the Firebase console, the configuration you chose\nthere will be suggested.\n\nSet up the emulator **Note:** Usage of the emulator in the Firebase Data Connect VS Code extension is covered in [Get started with Firebase Data Connect](/docs/data-connect/quickstart).\n\nConfigure the emulator\n\nRunning the `firebase init` flow will guide you through emulator setup options.\nLike other emulators in the Local Emulator Suite, configuration parameters\nare stored in local project files.\n\n- Your `firebase.json` file contains emulator port assignments.\n - The `emulators:ui` key does not apply to the Data Connect emulator.\n\nWork with local and production Data Connect resources\n\nIf you want to be sure not to impact production resources, set a `demo-`\nprojectID or make sure your client code is instrumented to connect to\nthe emulator, as discussed in a later section.\n\nStart the emulator\n\nIf you're running the emulator non-interactively, for example for CI/CD\nworkflows, start it with the `exec` option. \n\n firebase emulators:exec ./path/to/test-script.sh\n\nIf you're integrating predefined queries and mutations in client code and are\nusing the emulator specifically for testing clients, you can use the `start`\noption for interactive work. You can also start the emulator from the VS Code\nextension. \n\n firebase emulators:start\n\n| **Note:** When you start the emulator with `firebase emulators:start`, SDK code will be automatically generated just as if you had run `firebase sdk:generate`.\n\nInstrument your client code to talk to the emulator\n\nSet up your in-app configuration or test classes to interact with the\nData Connect emulator as follows. \n\nJavaScript \n\n```javascript\nimport { initializeApp } from \"firebase/app\";\nimport { connectorConfig } from \"@name-of-package\";\nimport { connectDataConnectEmulator, getDataConnect } from 'firebase/data-connect';\n\n// TODO: Replace the following with your app's Firebase project configuration\nconst firebaseConfig = {\n //...\n};\n\nconst app = initializeApp(firebaseConfig);\n\nconst dataConnect = getDataConnect(app, connectorConfig);\nconnectDataConnectEmulator(dataConnect, \"localhost\", 9399);\n\n// Make calls from your app\n \n```\n\nKotlin Android \n\n```kotlin\nval connector = MoviesConnector.instance\n\n// Connect to the emulator on \"10.0.2.2:9399\"\nconnector.dataConnect.useEmulator()\n\n// (Alternatively) if you're running your emulator on non-default port:\nconnector.dataConnect.useEmulator(port = 9999)\n\n// Make calls from your app\n \n```\n\niOS \n\n```text\nlet connector = DataConnect.dataConnect(DefaultConnectorClient.connectorConfig)\n\n// Connect to the emulator on \"127.0.0.1:9399\"\nconnector.useEmulator()\n\n// (alternatively) if you're running your emulator on non-default port:\nconnector.useEmulator(port: 9999)\n\n// Make calls from your app\n \n```\n\nUse the emulator for testing and continuous integration\n\nRun containerized Local Emulator Suite images\n\nInstallation and configuration of the Local Emulator Suite with containers\nin a typical CI setup is straightforward.\n\nThere are a few issues to note:\n\n- Emulator binaries are installed and cached at `~/.cache/firebase/emulators/`. You may want to add this path to your CI cache configuration to avoid repeated downloads.\n- If you don't have a `firebase.json` file in your repository, you must add a command line argument to the `emulators:start` or `emulators:exec` command to specify which emulators should be started. For example, `--only dataconnect`.\n\nClear your database between tests\n\nTo reset your test environments between runs, Firebase recommends:\n\n- Writing dedicated mutations to handle the following:\n - In setup, populate a local database instance with starting data.\n - In teardown, delete modified data from post-test database instance.\n\nHow the Data Connect emulator differs from production\n\nThe Data Connect emulator simulates many features of the server-side\nproduct. However, there are some exceptions to be aware of:\n\n- The version and detailed configuration of PGLite may differ from the version of your production Cloud SQL instance.\n- If you're using the emulator to develop with Data Connect's pgvector and Vertex API integration, calls to the Cloud Vertex API are made directly, rather than through Cloud SQL's Vertex integration. However, calls to the production API are still made, meaning you must use a real Firebase project, cannot use a `demo-` project, and costs of the Vertex API will be incurred."]]