انتقل إلى المحتوى الرئيسي

استيراد الأنواع

كل واجهة عامة ونوع من SDK يتم إعادة تصديرها من جذر الحزمة ومن نقطة دخول مخصصة oneentry/types، لذا لم تعد هناك حاجة لمسارات عميقة oneentry/dist/....

النسخة القصيرة

// before — deep path into the build output
import type { IAttributeSchemaItem, IAttributeSetsEntity } from 'oneentry/dist/attribute-sets/attributeSetsInterfaces';

// now — either of these
import type { IAttributeSchemaItem, IAttributeSetsEntity } from 'oneentry';
import type { IAttributeSchemaItem, IAttributeSetsEntity } from 'oneentry/types';

كلا نقطتي الدخول تعرضان نفس مجموعة الأنواع — كل واجهة ونوع من كل وحدة، بما في ذلك المشتركة من base/utils (IError, IAttributeValues, ILocalizeInfo, IConfig, …).

أي نقطة دخول يجب أن أستخدم؟

الاستيراد مناستخدمها عندما
'oneentry'إذا كنت تستورد بالفعل defineOneEntry (أو مساعد) من الجذر — سطر استيراد واحد يغطي القيم والأنواع.
'oneentry/types'إذا كنت تريد وحدة تحتوي على الأنواع فقط: فهي لا تحمل أي كود وقت التشغيل على الإطلاق، مما يبقي الملفات التي تحتوي على الأنواع فقط (*.d.ts، ملفات النموذج المشتركة، عقود API) خالية من أي استيراد للقيم.

لا يوجد فرق وظيفي بينهما — اختر أيهما يبدو أفضل في مشروعك.

خلط القيم والأنواع

نقطة الدخول الجذرية تصدر كل من واجهة برمجة التطبيقات وقت التشغيل والأنواع، لذا غالبًا ما يكون سطر واحد كافيًا:

import { defineOneEntry } from 'oneentry';
import type { IConfig, IError, IProductsEntity } from 'oneentry';

const config: IConfig = { token: 'your-app-token' };
const api = defineOneEntry('https://my-project.oneentry.cloud', config);

const products: IProductsEntity[] | IError = await api.Products.getProducts();

استخدم import type (أو import { type X }) للأنواع: يتم محو الاستيراد في وقت الترجمة، لذا لا يساهم أبدًا في حزمة المشروع الخاصة بك.

الاستيرادات العميقة لا تزال تعمل

لم يتم إزالة أي شيء. الكود الموجود الذي يستورد من oneentry/dist/<module>/<module>Interfaces يستمر في الترجمة تمامًا كما كان من قبل — نقاط الدخول الجديدة هي إضافات، لذا يمكنك الانتقال من ملف إلى آخر بالوتيرة التي تناسبك.

// still valid
import type { IOrderData } from 'oneentry/dist/orders/ordersInterfaces';

من أين تأتي الأنواع؟

كل وحدة من SDK تساهم بواجهاتها الخاصة، وكلها تنتهي تحت كلا نقطتي الدخول:

الوحدةالأنواع النموذجية
ProductsIProductsEntity, IProductsResponse, IProductsQueryBase, IFilterParams
PagesIPagesEntity, IPositionBlock, PageType
BlocksIBlocksEntity, BlockType, IContentSlidesResponse
OrdersIOrderData, IBaseOrdersEntity, IOrderByMarkerEntity, IRefundRequest
UsersIUserEntity, ICartResponse, IWishlistResponse
Forms / FormDataIFormsEntity, IFormAttribute, IBodyPostFormData
AttributesSetsIAttributeSetsEntity, IAttributeSchemaItem
مشترك (base/utils)IError, IConfig, IAttributeValues, IAttributeValue, ILocalizeInfo, LangType

القائمة الكاملة لأنواع الوحدة موثقة في صفحة مقدمة تلك الوحدة.

التحقق من الأخطاء

IError هو النوع وراء وضع SDK الافتراضي "الأخطاء كقيم" (isShell: true)، وهو متاح من الجذر مثل كل شيء آخر:

import type { IError } from 'oneentry';

function isErrorResult(result: unknown): result is IError {
return (
!!result &&
typeof result === 'object' &&
('statusCode' in result || 'message' in result)
);
}

const result = await api.Products.getProducts();

if (isErrorResult(result)) {
console.error('Error:', result.message);
} else {
console.log('Success:', result);
}

🔗 الوثائق ذات الصلة