fix: 接入抖音原生支付并修复App支付服务缺失

This commit is contained in:
Codex
2026-09-09 12:00:13 +08:00
parent b350f1c07a
commit fe8cc21bfe
155 changed files with 11995 additions and 634 deletions
+18
View File
@@ -0,0 +1,18 @@
{
"id": "tb-douyin-pay",
"displayName": "TB 抖音支付",
"version": "0.1.0",
"description": "独立实现的抖音支付官方 SDK UTS 桥接",
"engines": { "HBuilderX": ">=4.36.0" },
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"client": {
"App": { "app-android": "y", "app-ios": "y", "app-harmony": "n" },
"H5-mobile": { "Safari": "n", "Android Browser": "n" },
"小程序": { "微信": "n" }
}
}
}
}
@@ -0,0 +1,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.INTERNET" />
<queries>
<package android:name="com.ss.android.ugc.aweme" />
<package android:name="com.ss.android.ugc.aweme.lite" />
<package android:name="com.ss.android.ugc.live" />
</queries>
</manifest>
@@ -0,0 +1,50 @@
package uts.sdk.modules.tbDouyinPay
import android.os.Handler
import android.os.Looper
import com.ss.android.dypay.api.DyPay
import com.ss.android.dypay.api.IDyPayResultCallback
import io.dcloud.uts.UTSAndroid
import org.json.JSONObject
object TbDouyinPayNative {
private val main = Handler(Looper.getMainLooper())
fun initialize(appId: String) { DyPay.setAppId(appId) }
fun available(): Boolean {
val activity = UTSAndroid.getUniActivity() ?: return false
return DyPay.isDypayAppUsable(activity)
}
fun pay(payload: String, loading: Boolean, done: (String) -> Unit) {
main.post {
val activity = UTSAndroid.getUniActivity()
if (activity == null || activity.isFinishing) {
done("""{"resultCode":"2","errorMsg":"当前页面不可用"}""")
return@post
}
try {
if (!DyPay.isDypayAppUsable(activity)) {
done("""{"resultCode":"100","errorMsg":"请安装或升级抖音客户端"}""")
return@post
}
val json = JSONObject(payload)
val data = HashMap<String, String>()
for (key in listOf("appid", "partnerid", "prepayid", "package", "noncestr", "timestamp", "sign")) {
data[key] = json.getString(key)
}
DyPay(activity).pay(data, object : IDyPayResultCallback {
override fun onResult(result: Map<String, String>) {
val response = JSONObject()
.put("resultCode", result["resultCode"] ?: "3")
.put("errorMsg", result["errorMsg"] ?: "")
main.post { done(response.toString()) }
}
}, loading)
} catch (_: Exception) {
done("""{"resultCode":"2","errorMsg":"支付 SDK 调用异常,请查询订单"}""")
}
}
}
}
@@ -0,0 +1,7 @@
{
"minSdkVersion": 21,
"dependencies": ["com.bytedance.caijing:dy-pay-sdk-tob:1.1.0.9"],
"project": {
"repositories": ["maven { url 'https://artifact.bytedance.com/repository/Volcengine/' }"]
}
}
@@ -0,0 +1,18 @@
import { InitOptions, PayOptions, PayCallback } from '../interface.uts'
import { configure, invoke } from '../common.uts'
export function initDypay(options: InitOptions): boolean {
if (!configure(options.appId)) return false
TbDouyinPayNative.initialize(options.appId)
return true
}
export function canOpenDypay(): boolean {
return TbDouyinPayNative.available()
}
export function openDypay(options: PayOptions, callback: PayCallback): void {
invoke(options, callback, (payload: string, loading: boolean, done: (raw: string) => void) => {
TbDouyinPayNative.pay(payload, loading, done)
})
}
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AvailableLibraries</key>
<array>
<dict>
<key>BinaryPath</key>
<string>DypaySDK.framework/DypaySDK</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>DypaySDK.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>DypaySDK.framework/DypaySDK</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>DypaySDK.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
</dict>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>
@@ -0,0 +1,4 @@
#import <Foundation/Foundation.h>
#import "DypayDIRSFMDatabase.h"
#import "DypayDIRSFMResultSet.h"
#import "DypayDIRSFMDatabaseQueue.h"
@@ -0,0 +1,149 @@
//
// DypayAPI.h
// DypaySDK
//
// Created by xutianxi on 2021/12/10.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, DypayErrorCode) {
DypayErrorCodeSuccess = 0, // 成功
DypayErrorCodeCancel = 1, // 用户取消
DypayErrorCodeFail = 2, // 失败
DypayErrorCodeProcessing = 3, // 支付结果处理中
DypayErrorCodeVersionTooLow = 100, // 抖音版本过低,需要用户升级
};
typedef NS_ENUM(NSInteger, DypayLogLevel) {
DypayLogLevelOff = 0,
DypayLogLevelError = 1,
DypayLogLevelWarn = 2,
DypayLogLevelInfo = 3,
DypayLogLevelDebug = 4,
};
#define DYPAYSDK_TAG @"DypaySDK"
#define DYPAY_RECALL_API_MAX_TIME 3000 //毫秒级
#define SHARED_SELF DypayAPI.sharedDypayAPI
@interface DypayAPI : NSObject
// 日志记录Block,可查看运行过程中的信息
@property (nonatomic, copy) void(^logBlock)(DypayLogLevel level, NSTimeInterval timestamp, NSString *tag, NSString *message);
/**
* 支付单例
*
* @return 返回单例对象
*/
+ (DypayAPI *)sharedDypayAPI;
/*
* @param appId 从抖音商户平台申请的appId
* @param scheme 从抖音回调当前 App 时使用的 scheme
*/
+ (void)registerWithAppID:(NSString *)appId
callbackScheme:(NSString *)scheme;
/*
* @param appId 从抖音商户平台申请的appId,优先使用universalLink,降级使用scheme
* @param universalLink 从抖音回调当前 App 时使用的universalLink
* @param scheme 从抖音回调当前 App 时使用的 scheme
*/
+ (void)registerWithAppID:(NSString *)appId
universalLink:(NSString *)universalLink
callbackScheme:(NSString *)scheme;
/*
* 判断是否能打开 Dypay
*/
+ (bool)canOpenDypay;
/*
* @brief 打开 Dypay, 打开成功后马上回调 completionBlock,
* @param infoDict 拉起抖音支付必须的订单参数
* @param currentTopViewController 拉起抖音支付时顶部的vc
* @param callback 调用结果的回调
*/
+ (void)openDypayWithInfo:(NSDictionary *)infoDict
fromViewController:(UIViewController *)currentTopViewController
callback:(void(^)(BOOL isOpenedSuccessed, NSString *errMsg))completionBlock DEPRECATED_MSG_ATTRIBUTE("call openDypayWithInfo:fromViewController:resultCallback instead");
/*
* @brief 打开 Dypay,唤端之前:支付结果会通过该API的resultCallback参数回调,唤端之后:支付结果通过processDypayResultWithURL的callback回调
* @param infoDict 拉起抖音支付必须的订单参数
* @param currentTopViewController 拉起抖音支付时顶部的vc
* @param resultCallback 支付结果的回调,resultCode枚举参照processDypayResultWithURL注释
*/
+ (void)openDypayWithInfo:(NSDictionary *)infoDict
fromViewController:(UIViewController *)currentTopViewController
resultCallback:(void(^)(NSDictionary *resultDict))resultCompletionBlock;
/*
* 处理通过URL支付回调结果
* resultDict 包含支付结果错误码信息,如果为nil也表示处理失败。
字典中,key: "resultStatus"对应老的错误码定义,将逐步废弃;请使用新key: "resultCode"对应的错误码定义。
老key: resultStatus,对应的错误码定义:
-1 未知
0 订单支付成功
10 用户中途取消
20 正在处理中
30 版本过低
40 失败
50 超时
新key: resultCode,对应的错误码定义
DypayErrorCodeSuccess(0) 成功
DypayErrorCodeCancel(1) 用户取消
DypayErrorCodeFail(2) 失败
DypayErrorCodeProcessing(3) 支付结果处理中
DypayErrorCodeVersionTooLow(100) 抖音版本过低,需要用户升级
*/
+ (BOOL)processDypayResultWithURL:(NSURL *)url
callback:(void(^)(NSDictionary * _Nullable resultDict))completionBlock;
/*
* 处理通过Universal Link支付回调结果
* resultDict 包含支付结果错误码信息,如果为nil也表示处理失败。
字典中,key: "resultStatus"对应老的错误码定义,将逐步废弃;请使用新key: "resultCode"对应的错误码定义。
老key: resultStatus,对应的错误码定义:
-1 未知
0 订单支付成功
10 用户中途取消
20 正在处理中
30 版本过低
40 失败
50 超时
新key: resultCode,对应的错误码定义
DypayErrorCodeSuccess(0) 成功
DypayErrorCodeCancel(1) 用户取消
DypayErrorCodeFail(2) 失败
DypayErrorCodeProcessing(3) 支付结果处理中
DypayErrorCodeVersionTooLow(100) 抖音版本过低,需要用户升级
*/
+ (BOOL)processDypayResultWithUserActivity:(NSUserActivity *)userActivity
callback:(void(^)(NSDictionary *resultDict))completionBlock;
/*! @brief 获取当前 DypaySDK API 的版本号
*/
+ (NSString *)getAPIVersion;
/*
* 埋点
*/
+ (void)event:(NSString *_Nonnull)eventName params:(NSDictionary *_Nullable)params;
@end
// 内部接口,字节外部App不应使用
@interface DypayAPI (Internal)
// 业务埋点上报Block,字节内部App使用时设置
@property (nonatomic, copy) void(^trackEventBlock)(NSString *event, NSDictionary *params);
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,32 @@
//
// DypayDIRSApplication.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/13.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, DypayIRISApplicationState) {
DypayIRISApplicationStateUnknown = 0,
DypayIRISApplicationStateActive,
DypayIRISApplicationStateInactive,
DypayIRISApplicationStateBackground
};
@interface DypayDIRSApplication : NSObject
@property (readonly, nonnull) NSString *launchID;
@property (readonly, assign) NSTimeInterval launchTime;
@property (readonly) DypayIRISApplicationState applicationState;
+ (instancetype)sharedApplication;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,20 @@
//
// DypayDIRSBasicFeatureOptions.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/11/9.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSBasicFeatureOptions : DypayDIRSBasicModule
- (void)addFeatureOptions:(NSDictionary *)opts;
- (void)removeFeatureOptionsKeys:(NSArray *)keys;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,35 @@
//
// DypayDIRSBasicModule.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/11.
//
#import <Foundation/Foundation.h>
#import "DypayIRISInterfaceDefines.h"
#import "DypayIRISMacro.h"
#import "DypayDIRSContext.h"
#import "DypayDIRSModuleHive.h"
#import "IRSLOG.h"
#import "DypayDataIRIS.h"
NS_ASSUME_NONNULL_BEGIN
@class DypayDIRSContext;
@interface DypayDIRSBasicModule : NSObject<DypayIRISModule>
@property (nonatomic, weak) DypayDIRSContext* context;
@property (nullable, nonatomic, copy) NSString* category;
@property BOOL isEnabled;
@property DypayIRISState state;
- (void)onLaunch;
- (void)run;
- (void)stop;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,16 @@
//
// DypayDIRSCompressionGzipPlugin.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/8/9.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSCompressionGzipPlugin : DypayDIRSBasicModule<DypayIRISModuleGlobal, DypayIRISDataCoder>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,24 @@
//
// DypayDIRSConcurrentCollection.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/11.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSConcurrentCollection<T> : NSObject
+ (instancetype)collectionWithRaw:(T)collection;
- (void)operate:(void (^)(T raw))operation;
- (nullable id)access:(nullable id (^)(T raw))operation;
- (T)rawValue;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,193 @@
//
// DypayDIRSConfig.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/11.
//
#import <Foundation/Foundation.h>
#import "DypayIRISDefines.h"
NS_ASSUME_NONNULL_BEGIN
@class DypayDIRSComplianceConfiguration,DypayDIRSEventConfiguration,DypayDIRSObserver,DypayDIRSEventUploadFilterOptions;
@interface DypayDIRSConfig : NSObject
+ (instancetype _Nullable)configWithIdentifier:(NSString *_Nonnull)appId
launchOptions:(nullable NSDictionary *)launchOptions;
@property (nullable, nonatomic, copy) NSString *appId;
@property (nullable, nonatomic, copy) NSString *appName;
@property (nullable, nonatomic, copy) NSString *appVersion;
@property (nullable, nonatomic, copy) NSString *buildVersion;
//If you need to synchronize data between HostApp and ExtensionApp, you need to set the same groupId
@property (nullable, nonatomic, copy) NSString *appGroupId;
@property (nullable, nonatomic, copy) NSString *channel;
//be able to distinguish between different instances using the same appid
@property (nullable, nonatomic, copy) NSString *subId;
@property (nonatomic, strong ) NSDictionary *launchOptions;
@property (nonatomic, assign) BOOL encryptionEnabled;
@property (nullable, nonatomic, strong) id<DypayIRISEndpoint> endpoint;
///The default log level is Error
@property (nonatomic, assign) DypayIRISLOG_LEVEL logLevel;
@property (nullable, nonatomic, copy) void (^configureUserLoggerBlock)(id<DypayIRISLog> _Nullable log);
@property (nullable, readonly) DypayDIRSComplianceConfiguration* compliance;
@property (nullable, readonly) DypayDIRSEventConfiguration* event;
@property (nullable, readonly) DypayDIRSObserver *observer;
@property (nullable, nonatomic, copy) NSDictionary<NSString*, NSString *> *_Nullable (^configureHTTPHeaderFieldsBlock)(NSUInteger service);
@property (nullable, nonatomic, copy) NSDictionary<NSString*, id> *_Nullable (^configureCommonParametersBlock)(NSUInteger service);
@property (nullable, nonatomic, copy) NSDictionary<NSString*, id> *_Nullable (^configureCustomHeaderBlock)(NSUInteger service);
@property (nullable, nonatomic, copy) void (^onError)(BOOL fatal, NSError * _Nonnull error, id _Nullable userInfo);
@end
@interface DypayDIRSComplianceConfiguration : NSObject
/**
* @brief fields to avoid access
*
* @discussion Fields set in @c blockedFiels will not be accessed and uploaded.
* For example, if you you do not want to collect @c vendor_id, set the following code block, then @c UIDevice.identifierForVendor will not be accessed, and the field @c vendor_id will not appear in any HTTPBODY
*
* @code
* config.compliance.blockedFields = @[@"vendor_id"];
* @endcode
*
*/
@property (nullable, nonatomic, copy) NSArray *blockedFields;
@end
@interface DypayDIRSEventConfiguration : NSObject
/*
* Intercept or change events before they are stored
*/
@property (nullable, nonatomic, copy) void (^configureEventInterceptorBlock)(id<DypayIRISEvent> _Nullable event, BOOL * _Nonnull stop);
/*
* Filter events before packaging
*
*/
@property (nullable, nonatomic, copy) _Nullable id (^configurePreBatchFilterBlock)(id _Nullable context);
@property (nullable, nonatomic, copy) _Nullable id (^configureEventPacketBlock)(id<DypayIRISEvent> _Nullable event, BOOL * _Nonnull stop);
/*
*
* Event expiration time [Unit:seconds]
* Data will be cleaned based on expiration time every time on startup
* Setting it to 0 will not clean up the data.
*
* Default is 0
*
*/
@property (nonatomic, assign) NSUInteger eventExpirationTime;
/*
* - DypayIRISEventPacketStrategyDefault
* Packaging based on the upper limit of the number of events, The number of upper limit can be set through maxPacketEventCount, the default is 200
* - DypayIRISEventPacketStrategyByteLimitation
* Packing based on the upper limit of data length, The length can be set through maxPacketBytes, the default is 1024*1024
*
* Default is DypayIRISEventPacketStrategyDefault
*
*/
@property (nonatomic, assign) DypayIRISEventPacketStrategy packetStrategy;
/*
*
* Default is 200
* takes effect when setting config.event.packetStrategy = DypayIRISEventPacketStrategyDefault
*
*/
@property (nonatomic, assign) NSUInteger maxPacketEventCount;
/*
*
* Default is 1m
* takes effect when setting config.event.packetStrategy = DypayIRISEventPacketStrategyByteLimitation
*
*/
@property (nonatomic, assign) NSUInteger maxPacketBytes;
/*
* Default is 500m, some(25%) earliest events will be deleted when the maximum limit is exceeded on startup
When an error occurs in the data file and the size of the database file cannot be successfully reduced
in order to avoid affecting the stability of the application,
the database file will be removed as a whole, which will cause events loss
*/
@property (nonatomic, assign) NSUInteger maxFileBytes;
/*
* Maximum length after serialization
* default 20*1024;
*
* @NOT take effect yet
*/
@property (nonatomic, assign) NSUInteger maxPropertyBytes;
@end
@interface DypayDIRSEventUploadFilterOptions : NSObject
@property (nullable, nonatomic, strong) NSArray<NSString *> *regionKeys;
@property (nullable, nonatomic, strong) NSArray<NSString *> *includeTypes;
@property (nullable, nonatomic, strong) NSArray<NSString *> *excludeTypes;
@end
@interface DypayDIRSObserver : NSObject
@property (nullable, nonatomic, copy) void (^onSessionLaunch)(NSString *sessionId, id _Nullable info);
@property (nullable, nonatomic, copy) void (^onSessionTerminate)(NSString *sessionId, id _Nullable info);
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,67 @@
//
// DypayDIRSContext.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/11.
//
#import <Foundation/Foundation.h>
#import "DypayIRISInterfaceDefines.h"
NS_ASSUME_NONNULL_BEGIN
@class DypayDIRSConfig,DypayDIRSLogger,DypayDIRSModuleHive;
@interface DypayDIRSContext : NSObject
@property (nonatomic, readonly) DypayDIRSModuleHive* modular;
@property (readonly, nullable) DypayDIRSConfig *config;
@property (readonly, nonnull) NSString *name;
+ (instancetype)main;
+ (void)configure:(DypayDIRSConfig *)config;
- (instancetype)initWithConfig:(DypayDIRSConfig *)config;
- (BOOL)resume;
- (void)suspend;
- (nonnull NSString *)contextPath;
- (void)async:(dispatch_block_t)block;
- (nonnull NSDictionary *)contextInfo;
- (void)dispose;
- (BOOL)isMainContext;
@end
@interface DypayDIRSContext (Instance)
+ (NSArray<DypayDIRSContext *> *)ctx_all;
+ (nullable DypayDIRSContext *)ctx_get:(NSString *)name;
+ (void)ctx_add:(DypayDIRSContext *)context;
+ (void)ctx_remove:(DypayDIRSContext *)context;
@end
@interface DypayDIRSContext (Modules)
@property (nullable, nonatomic, readonly) DypayDIRSLogger *logger;
- (nullable NSDictionary *)modules;
+ (NSDictionary *)defaultModules;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,25 @@
//
// DypayDIRSEndpointConfiguration.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/24.
//
#import <Foundation/Foundation.h>
#import "DypayIRISDefines.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEndpointConfiguration : NSObject<DypayIRISEndpoint>
@property (nullable, nonatomic, copy) id _Nullable (^domainBlock)(NSUInteger service, id context);
@property (nullable, nonatomic, copy) id _Nullable (^endpointBlock)(NSUInteger service, id context);
+ (DypayDIRSEndpointConfiguration *)configurationUsingBlock:(nonnull id (^)(NSUInteger service, id context))block;
+ (DypayDIRSEndpointConfiguration *)configurationUsingDomainBlock:(nonnull id (^)(NSUInteger service, id context))block;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,29 @@
//
// DypayDIRSEnviroment.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/25.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEnviroment : DypayDIRSBasicModule<DypayIRISParameterHandler,DypayIRISModuleGlobal>
+ (NSInteger)sdkVersion;
+ (NSString *)sdkVersionString;
+ (NSString *)osName;
+ (NSString *)osVersion;
+ (NSString *)platform;
+ (NSString *)appVersion;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,34 @@
//
// DypayDIRSErrorBuilder.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/13.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSErrorBuilder : NSObject
+ (instancetype)builder;
- (instancetype)withDomain:(NSErrorDomain)code;
- (instancetype)withCode:(NSUInteger)code;
- (instancetype)withDescription:(NSString *)description;
- (instancetype)withDescriptionFormat:(NSString *)format, ...;
- (instancetype)withFailureReason:(NSString *)reason;
- (instancetype)withUnderlyingError:(NSError *)error;
- (NSError *)build;
- (BOOL)buildError:(NSError **)error;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,106 @@
//
// DypayDIRSEvent.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/13.
//
#import <Foundation/Foundation.h>
#import "DypayIRISDefinesPrivate.h"
typedef NSString * DypayIRISEventType;
FOUNDATION_EXTERN DypayIRISEventType const _Nonnull DypayDIRSEventTypeV3; //event_v3
NS_ASSUME_NONNULL_BEGIN
@class DypayDIRSEventOptions;
@interface DypayDIRSEvent : NSObject<DypayIRISEvent, NSCoding>
@property (nullable, nonatomic, copy) NSString * key;
@property (nullable, nonatomic, copy) NSString * type;
@property (nonatomic) NSTimeInterval time;
@property (nonatomic) NSTimeInterval storedTime;
@property (nonatomic) NSTimeInterval batchedTime;
@property (nullable, nonatomic, strong) NSDictionary * properties;
@property (nullable, nonatomic, strong) NSDictionary * globalProperties;
@property (nullable, nonatomic, strong) NSDictionary * commonParameters;
@property (nullable, nonatomic, copy) NSString * logID;
@property (nullable, nonatomic, copy) NSNumber* dbIndex;
@property (nonatomic, assign) int64_t index;
@property (nonatomic, copy) NSString* section;
@property (nullable, nonatomic) id schemaObject;
@property (nonatomic, assign) NSUInteger schemaDataLength;
@property (nonatomic, strong) DypayDIRSEventOptions * options;
@property (nonatomic, assign) BOOL stained;
//return event_id if event stained
- (int64_t)staining;
- (NSString *)sessionId;
- (void)addCommonParameters:(NSDictionary *)parameters;
+ (nullable instancetype)eventWithType:(DypayIRISEventType _Nonnull)type
properties:(NSDictionary * _Nullable)properties;
+ (nullable instancetype)v3UsingKey:(NSString * _Nonnull)key
properties:(NSDictionary * _Nullable)properties;
@end
@interface DypayDIRSEventOptions : NSObject
@property (nonatomic, assign) NSInteger category;
@property (nonatomic, assign) DypayIRISPriority priority;
@property (nullable ,nonatomic, copy) NSString * regionKey;
@property (nonatomic, assign) NSInteger privacyLevel;
@property (nonatomic, assign) BOOL filtered;
@end
@interface DypayDIRSEventBatchOptions : NSObject
@property (nonatomic, assign) NSInteger priority;
@property (nullable, nonatomic) NSArray * eventIDs;
@property (nonatomic, assign) NSUInteger count;
@property (nonatomic, strong) NSArray * allowRegionList;
@property (nonatomic, assign) NSInteger minDBIndex;
@property (nonatomic, assign) NSInteger maxDBIndex;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,29 @@
//
// DypayDIRSEventUploadDispatcher.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/18.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventBatchDispatcher : DypayDIRSBasicModule
@property (nonatomic, readonly) id<DypayIRISServiceSchema> schema;
@property (readonly) id<DypayIRISEventUploadExecutor> defaultUploader;
@property (readonly) id<DypayIRISEventUploadExecutor> realtimeUploader;
- (nullable id<DypayIRISEventUploadExecutor>)createExecutor;
- (nullable NSArray<DypayIRISEventUploadExecutor> *)allExecutors;
- (nonnull dispatch_queue_t)intervalBatchQueue;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,50 @@
//
// DypayDIRSEventUploadExecutor.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/18.
//
#import "DypayDIRSBasicModule.h"
#import "DypayIRISInterfaceDefines.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventBatchExecutor : DypayDIRSBasicModule<DypayIRISEventUploadExecutor>
@property (nonatomic, assign) NSTimeInterval interval;
@property (nullable, nonatomic, weak) id<DypayIRISServiceSchema> serializer;
@property (nullable, nonatomic) NSArray<id<DypayIRISDataCoder>> *compressors;
@property (nullable, nonatomic, weak) id<DypayIRISDataCoder> encryptor;
@property (nullable, nonatomic, weak) id<DypayIRISDataCoder> decryptor;
@property (nullable, nonatomic, weak) id<DypayIRISEventStore> eventStore;
@property (nullable, nonatomic) id<DypayIRISThrottlter> throttlter;
@property (nonatomic, assign) DypayIRISPriority priority;
@property (nonatomic, assign) DypayIRISState execState;
@property (nullable, nonatomic, strong) NSDictionary *options;
/*
* @opts
* DypayIRISBatchOptionsEnforceKey - enforce batch YES|NO
*
*/
//- (void)executeUpload:(DypayIRISBatchTrigger)trigger
// options:(nullable NSDictionary *)opts
// completion:(void (^ __nullable)(BOOL success, NSError* _Nullable error))completion;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,16 @@
//
// DypayDIRSEventBlockPlugin.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/8/25.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventBlockPlugin : DypayDIRSBasicModule
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,18 @@
//
// DypayDIRSEventEntry.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/13.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventEntry : DypayDIRSBasicModule<DypayIRISModule, DypayIRISTracker>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,17 @@
//
// DypayDIRSEventListener.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/8/14.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventListener : DypayDIRSBasicModule
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,22 @@
//
// DypayDIRSEventPacker.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/18.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventPacker : NSObject<DypayIRISEventPacker>
@property (nonatomic, assign) NSUInteger maxPackLength;
@property (nonatomic, assign) NSUInteger maxEventCount;
@property (nonatomic, assign) NSInteger strategy;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,23 @@
//
// DypayDIRSEventRequestSchema.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/18.
//
#import "DypayDIRSBasicModule.h"
#import "DypayDIRSEventPacker.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventRequestSchema : DypayDIRSBasicModule<DypayIRISServiceSchema,DypayIRISModuleGlobal>
@end
@interface DypayDIRSEventRealtimeRequestSchema : DypayDIRSEventRequestSchema<DypayIRISServiceSchema, DypayIRISModuleGlobal>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,16 @@
//
// DypayDIRSEventSerializer.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/14.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventSerializer : DypayDIRSBasicModule<DypayIRISEventSerializer>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,20 @@
//
// DypayDIRSEventSession.h
//
//
// Created by ByteDance on 2023/8/4.
//
#import "DypayDIRSBasicModule.h"
#import "DypayDataIRIS.h"
#import "DypayDIRSTracker+Session.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventSession : DypayDIRSBasicModule
@property (nonatomic, assign) DypayIRISLaunchType launchType;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,24 @@
//
// DypayDIRSEventStore.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/13.
//
#import "DypayDIRSBasicModule.h"
#import "DypayDIRSEvent.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventStore : DypayDIRSBasicModule<DypayIRISEventStore>
@property (nonatomic, weak) id<DypayIRISEventSerializer> serializer;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,31 @@
//
// DypayDIRSExtension.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/11.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface NSDictionary (DypayDataIRIS)
- (nullable NSDictionary *)datairis_dictionaryForKey:(NSString *)key;
- (nullable NSString *)datairis_stringForKey:(NSString *)key;
- (nullable NSArray *)datairis_arrayForKey:(NSString *)key;
- (double)datairis_doubleForKey:(NSString *)key;
- (NSInteger)datairis_integerForKey:(NSString *)key;
- (BOOL)datairis_boolForKey:(NSString *)key;
- (long long)datairis_longlongValueForKey:(NSString *)key;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,182 @@
//
// DypayDIRSFMDatabaseQueue.h
// fmdb
//
// Created by August Mueller on 6/22/11.
// Copyright 2011 Flying Meat Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
@class DypayDIRSFMDatabase;
/** To perform queries and updates on multiple threads, you'll want to use `DypayDIRSFMDatabaseQueue`.
Using a single instance of `<DypayDIRSFMDatabase>` from multiple threads at once is a bad idea. It has always been OK to make a `<DypayDIRSFMDatabase>` object *per thread*. Just don't share a single instance across threads, and definitely not across multiple threads at the same time.
Instead, use `DypayDIRSFMDatabaseQueue`. Here's how to use it:
First, make your queue.
DypayDIRSFMDatabaseQueue *queue = [DypayDIRSFMDatabaseQueue databaseQueueWithPath:aPath];
Then use it like so:
[queue inDatabase:^(DypayDIRSFMDatabase *db) {
[db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:1]];
[db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:2]];
[db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:3]];
DypayDIRSResultSet *rs = [db executeQuery:@"select * from foo"];
while ([rs next]) {
//…
}
}];
An easy way to wrap things up in a transaction can be done like this:
[queue inTransaction:^(DypayDIRSFMDatabase *db, BOOL *rollback) {
[db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:1]];
[db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:2]];
[db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:3]];
if (whoopsSomethingWrongHappened) {
*rollback = YES;
return;
}
// etc…
[db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:4]];
}];
`DypayDIRSFMDatabaseQueue` will run the blocks on a serialized queue (hence the name of the class). So if you call `DypayDIRSFMDatabaseQueue`'s methods from multiple threads at the same time, they will be executed in the order they are received. This way queries and updates won't step on each other's toes, and every one is happy.
### See also
- `<DypayDIRSFMDatabase>`
@warning Do not instantiate a single `<DypayDIRSFMDatabase>` object and use it across multiple threads. Use `DypayDIRSFMDatabaseQueue` instead.
@warning The calls to `DypayDIRSFMDatabaseQueue`'s methods are blocking. So even though you are passing along blocks, they will **not** be run on another thread.
*/
@interface DypayDIRSFMDatabaseQueue : NSObject {
NSString *_path;
dispatch_queue_t _queue;
DypayDIRSFMDatabase *_db;
int _openFlags;
}
/** Path of database */
@property (atomic, retain) NSString *path;
/** Open flags */
@property (atomic, readonly) int openFlags;
///----------------------------------------------------
/// @name Initialization, opening, and closing of queue
///----------------------------------------------------
/** Create queue using path.
@param aPath The file path of the database.
@return The `DypayDIRSFMDatabaseQueue` object. `nil` on error.
*/
+ (instancetype)databaseQueueWithPath:(NSString*)aPath;
/** Create queue using path and specified flags.
@param aPath The file path of the database.
@param openFlags Flags passed to the openWithFlags method of the database
@return The `DypayDIRSFMDatabaseQueue` object. `nil` on error.
*/
+ (instancetype)databaseQueueWithPath:(NSString*)aPath flags:(int)openFlags;
/** Create queue using path.
@param aPath The file path of the database.
@return The `DypayDIRSFMDatabaseQueue` object. `nil` on error.
*/
- (instancetype)initWithPath:(NSString*)aPath;
/** Create queue using path and specified flags.
@param aPath The file path of the database.
@param openFlags Flags passed to the openWithFlags method of the database
@return The `DypayDIRSFMDatabaseQueue` object. `nil` on error.
*/
- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags;
/** Create queue using path and specified flags.
@param aPath The file path of the database.
@param openFlags Flags passed to the openWithFlags method of the database
@param vfsName The name of a custom virtual file system
@return The `DypayDIRSFMDatabaseQueue` object. `nil` on error.
*/
- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags vfs:(NSString *)vfsName;
/** Returns the Class of 'DypayDIRSFMDatabase' subclass, that will be used to instantiate database object.
Subclasses can override this method to return specified Class of 'DypayDIRSFMDatabase' subclass.
@return The Class of 'DypayDIRSFMDatabase' subclass, that will be used to instantiate database object.
*/
+ (Class)databaseClass;
/** Close database used by queue. */
- (void)close;
///-----------------------------------------------
/// @name Dispatching database operations to queue
///-----------------------------------------------
/** Synchronously perform database operations on queue.
@param block The code to be run on the queue of `DypayDIRSFMDatabaseQueue`
*/
- (void)inDatabase:(void (^)(DypayDIRSFMDatabase *db))block;
/** Synchronously perform database operations on queue, using transactions.
@param block The code to be run on the queue of `DypayDIRSFMDatabaseQueue`
*/
- (void)inTransaction:(void (^)(DypayDIRSFMDatabase *db, BOOL *rollback))block;
/** Synchronously perform database operations on queue, using deferred transactions.
@param block The code to be run on the queue of `DypayDIRSFMDatabaseQueue`
*/
- (void)inDeferredTransaction:(void (^)(DypayDIRSFMDatabase *db, BOOL *rollback))block;
///-----------------------------------------------
/// @name Dispatching database operations to queue
///-----------------------------------------------
/** Synchronously perform database operations using save point.
@param block The code to be run on the queue of `DypayDIRSFMDatabaseQueue`
*/
// NOTE: you can not nest these, since calling it will pull another database out of the pool and you'll get a deadlock.
// If you need to nest, use DypayDIRSFMDatabase's startSavePointWithName:error: instead.
- (NSError*)inSavePoint:(void (^)(DypayDIRSFMDatabase *db, BOOL *rollback))block;
@end
@@ -0,0 +1,468 @@
#import <Foundation/Foundation.h>
#ifndef __has_feature // Optional.
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
#endif
#ifndef NS_RETURNS_NOT_RETAINED
#if __has_feature(attribute_ns_returns_not_retained)
#define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))
#else
#define NS_RETURNS_NOT_RETAINED
#endif
#endif
@class DypayDIRSFMDatabase;
@class DypayDIRSStatement;
/** Represents the results of executing a query on an `<DypayDIRSFMDatabase>`.
### See also
- `<DypayDIRSFMDatabase>`
*/
@interface DypayDIRSResultSet : NSObject {
DypayDIRSFMDatabase *_parentDB;
DypayDIRSStatement *_statement;
NSString *_query;
NSMutableDictionary *_columnNameToIndexMap;
}
///-----------------
/// @name Properties
///-----------------
/** Executed query */
@property (atomic, retain) NSString *query;
/** `NSMutableDictionary` mapping column names to numeric index */
@property (readonly) NSMutableDictionary *columnNameToIndexMap;
/** `DypayDIRSStatement` used by result set. */
@property (atomic, retain) DypayDIRSStatement *statement;
///------------------------------------
/// @name Creating and closing database
///------------------------------------
/** Create result set from `<DypayDIRSStatement>`
@param statement A `<DypayDIRSStatement>` to be performed
@param aDB A `<DypayDIRSFMDatabase>` to be used
@return A `DypayDIRSResultSet` on success; `nil` on failure
*/
+ (instancetype)resultSetWithStatement:(DypayDIRSStatement *)statement usingParentDatabase:(DypayDIRSFMDatabase*)aDB;
/** Close result set */
- (void)close;
- (void)setParentDB:(DypayDIRSFMDatabase *)newDb;
///---------------------------------------
/// @name Iterating through the result set
///---------------------------------------
/** Retrieve next row for result set.
You must always invoke `next` or `nextWithError` before attempting to access the values returned in a query, even if you're only expecting one.
@return `YES` if row successfully retrieved; `NO` if end of result set reached
@see hasAnotherRow
*/
- (BOOL)next;
/** Retrieve next row for result set.
You must always invoke `next` or `nextWithError` before attempting to access the values returned in a query, even if you're only expecting one.
@param outErr A 'NSError' object to receive any error object (if any).
@return 'YES' if row successfully retrieved; 'NO' if end of result set reached
@see hasAnotherRow
*/
- (BOOL)nextWithError:(NSError **)outErr;
/** Did the last call to `<next>` succeed in retrieving another row?
@return `YES` if the last call to `<next>` succeeded in retrieving another record; `NO` if not.
@see next
@warning The `hasAnotherRow` method must follow a call to `<next>`. If the previous database interaction was something other than a call to `next`, then this method may return `NO`, whether there is another row of data or not.
*/
- (BOOL)hasAnotherRow;
///---------------------------------------------
/// @name Retrieving information from result set
///---------------------------------------------
/** How many columns in result set
@return Integer value of the number of columns.
*/
- (int)columnCount;
/** Column index for column name
@param columnName `NSString` value of the name of the column.
@return Zero-based index for column.
*/
- (int)columnIndexForName:(NSString*)columnName;
/** Column name for column index
@param columnIdx Zero-based index for column.
@return columnName `NSString` value of the name of the column.
*/
- (NSString*)columnNameForIndex:(int)columnIdx;
/** Result set integer value for column.
@param columnName `NSString` value of the name of the column.
@return `int` value of the result set's column.
*/
- (int)intForColumn:(NSString*)columnName;
/** Result set integer value for column.
@param columnIdx Zero-based index for column.
@return `int` value of the result set's column.
*/
- (int)intForColumnIndex:(int)columnIdx;
/** Result set `long` value for column.
@param columnName `NSString` value of the name of the column.
@return `long` value of the result set's column.
*/
- (long)longForColumn:(NSString*)columnName;
/** Result set long value for column.
@param columnIdx Zero-based index for column.
@return `long` value of the result set's column.
*/
- (long)longForColumnIndex:(int)columnIdx;
/** Result set `long long int` value for column.
@param columnName `NSString` value of the name of the column.
@return `long long int` value of the result set's column.
*/
- (long long int)longLongIntForColumn:(NSString*)columnName;
/** Result set `long long int` value for column.
@param columnIdx Zero-based index for column.
@return `long long int` value of the result set's column.
*/
- (long long int)longLongIntForColumnIndex:(int)columnIdx;
/** Result set `unsigned long long int` value for column.
@param columnName `NSString` value of the name of the column.
@return `unsigned long long int` value of the result set's column.
*/
- (unsigned long long int)unsignedLongLongIntForColumn:(NSString*)columnName;
/** Result set `unsigned long long int` value for column.
@param columnIdx Zero-based index for column.
@return `unsigned long long int` value of the result set's column.
*/
- (unsigned long long int)unsignedLongLongIntForColumnIndex:(int)columnIdx;
/** Result set `BOOL` value for column.
@param columnName `NSString` value of the name of the column.
@return `BOOL` value of the result set's column.
*/
- (BOOL)boolForColumn:(NSString*)columnName;
/** Result set `BOOL` value for column.
@param columnIdx Zero-based index for column.
@return `BOOL` value of the result set's column.
*/
- (BOOL)boolForColumnIndex:(int)columnIdx;
/** Result set `double` value for column.
@param columnName `NSString` value of the name of the column.
@return `double` value of the result set's column.
*/
- (double)doubleForColumn:(NSString*)columnName;
/** Result set `double` value for column.
@param columnIdx Zero-based index for column.
@return `double` value of the result set's column.
*/
- (double)doubleForColumnIndex:(int)columnIdx;
/** Result set `NSString` value for column.
@param columnName `NSString` value of the name of the column.
@return `NSString` value of the result set's column.
*/
- (NSString*)stringForColumn:(NSString*)columnName;
/** Result set `NSString` value for column.
@param columnIdx Zero-based index for column.
@return `NSString` value of the result set's column.
*/
- (NSString*)stringForColumnIndex:(int)columnIdx;
/** Result set `NSDate` value for column.
@param columnName `NSString` value of the name of the column.
@return `NSDate` value of the result set's column.
*/
- (NSDate*)dateForColumn:(NSString*)columnName;
/** Result set `NSDate` value for column.
@param columnIdx Zero-based index for column.
@return `NSDate` value of the result set's column.
*/
- (NSDate*)dateForColumnIndex:(int)columnIdx;
/** Result set `NSData` value for column.
This is useful when storing binary data in table (such as image or the like).
@param columnName `NSString` value of the name of the column.
@return `NSData` value of the result set's column.
*/
- (NSData*)dataForColumn:(NSString*)columnName;
/** Result set `NSData` value for column.
@param columnIdx Zero-based index for column.
@return `NSData` value of the result set's column.
*/
- (NSData*)dataForColumnIndex:(int)columnIdx;
/** Result set `(const unsigned char *)` value for column.
@param columnName `NSString` value of the name of the column.
@return `(const unsigned char *)` value of the result set's column.
*/
- (const unsigned char *)UTF8StringForColumnName:(NSString*)columnName;
/** Result set `(const unsigned char *)` value for column.
@param columnIdx Zero-based index for column.
@return `(const unsigned char *)` value of the result set's column.
*/
- (const unsigned char *)UTF8StringForColumnIndex:(int)columnIdx;
/** Result set object for column.
@param columnName `NSString` value of the name of the column.
@return Either `NSNumber`, `NSString`, `NSData`, or `NSNull`. If the column was `NULL`, this returns `[NSNull null]` object.
@see objectForKeyedSubscript:
*/
- (id)objectForColumnName:(NSString*)columnName;
/** Result set object for column.
@param columnIdx Zero-based index for column.
@return Either `NSNumber`, `NSString`, `NSData`, or `NSNull`. If the column was `NULL`, this returns `[NSNull null]` object.
@see objectAtIndexedSubscript:
*/
- (id)objectForColumnIndex:(int)columnIdx;
/** Result set object for column.
This method allows the use of the "boxed" syntax supported in Modern Objective-C. For example, by defining this method, the following syntax is now supported:
id result = rs[@"employee_name"];
This simplified syntax is equivalent to calling:
id result = [rs objectForKeyedSubscript:@"employee_name"];
which is, it turns out, equivalent to calling:
id result = [rs objectForColumnName:@"employee_name"];
@param columnName `NSString` value of the name of the column.
@return Either `NSNumber`, `NSString`, `NSData`, or `NSNull`. If the column was `NULL`, this returns `[NSNull null]` object.
*/
- (id)objectForKeyedSubscript:(NSString *)columnName;
/** Result set object for column.
This method allows the use of the "boxed" syntax supported in Modern Objective-C. For example, by defining this method, the following syntax is now supported:
id result = rs[0];
This simplified syntax is equivalent to calling:
id result = [rs objectForKeyedSubscript:0];
which is, it turns out, equivalent to calling:
id result = [rs objectForColumnName:0];
@param columnIdx Zero-based index for column.
@return Either `NSNumber`, `NSString`, `NSData`, or `NSNull`. If the column was `NULL`, this returns `[NSNull null]` object.
*/
- (id)objectAtIndexedSubscript:(int)columnIdx;
/** Result set `NSData` value for column.
@param columnName `NSString` value of the name of the column.
@return `NSData` value of the result set's column.
@warning If you are going to use this data after you iterate over the next row, or after you close the
result set, make sure to make a copy of the data first (or just use `<dataForColumn:>`/`<dataForColumnIndex:>`)
If you don't, you're going to be in a world of hurt when you try and use the data.
*/
- (NSData*)dataNoCopyForColumn:(NSString*)columnName NS_RETURNS_NOT_RETAINED;
/** Result set `NSData` value for column.
@param columnIdx Zero-based index for column.
@return `NSData` value of the result set's column.
@warning If you are going to use this data after you iterate over the next row, or after you close the
result set, make sure to make a copy of the data first (or just use `<dataForColumn:>`/`<dataForColumnIndex:>`)
If you don't, you're going to be in a world of hurt when you try and use the data.
*/
- (NSData*)dataNoCopyForColumnIndex:(int)columnIdx NS_RETURNS_NOT_RETAINED;
/** Is the column `NULL`?
@param columnIdx Zero-based index for column.
@return `YES` if column is `NULL`; `NO` if not `NULL`.
*/
- (BOOL)columnIndexIsNull:(int)columnIdx;
/** Is the column `NULL`?
@param columnName `NSString` value of the name of the column.
@return `YES` if column is `NULL`; `NO` if not `NULL`.
*/
- (BOOL)columnIsNull:(NSString*)columnName;
/** Returns a dictionary of the row results mapped to case sensitive keys of the column names.
@returns `NSDictionary` of the row results.
@warning The keys to the dictionary are case sensitive of the column names.
*/
- (NSDictionary*)resultDictionary;
/** Returns a dictionary of the row results
@see resultDictionary
@warning **Deprecated**: Please use `<resultDictionary>` instead. Also, beware that `<resultDictionary>` is case sensitive!
*/
- (NSDictionary*)resultDict __attribute__ ((deprecated));
///-----------------------------
/// @name Key value coding magic
///-----------------------------
/** Performs `setValue` to yield support for key value observing.
@param object The object for which the values will be set. This is the key-value-coding compliant object that you might, for example, observe.
*/
- (void)kvcMagic:(id)object;
@end
@@ -0,0 +1,28 @@
//
// DypayDIRSGlobalTimer.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/12.
//
#import <Foundation/Foundation.h>
#import "DypayIRISInterfaceDefines.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSGlobalTimer : NSObject
+ (instancetype)globalTimer;
- (void)addTimer:(id<DypayIRISTimer> _Nullable)timer;
- (void)removeTimer:(id<DypayIRISTimer> _Nullable)timer;
- (void)startTimer;
- (void)stopTimer;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,29 @@
//
// DypayDIRSIdentity.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/13.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSIdentity : DypayDIRSBasicModule<DypayIRISModule>
//for all service
@property (readonly) BOOL isIdentifierAvailable;
@property (readonly, nullable) NSString *clientId;
- (void)setUserIdentifiers:(NSDictionary *)IDs;
- (void)setDeviceIdentifiers:(NSDictionary *)IDs;
- (NSDictionary *)userIdentifiers;
- (NSDictionary *)deviceIdentifiers;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,32 @@
//
// DypayDIRSLogger.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/11.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSConsoleLogger : DypayDIRSBasicModule<DypayIRISModule, DypayIRISLogger>
@end
@interface DypayDIRSLogger : DypayDIRSBasicModule<DypayIRISModule>
- (void)addLogger:(id<DypayIRISLogger>)logger;
- (void)removeLogger:(id<DypayIRISLogger>)logger;
- (void)removeAllLoggers;
- (void)addLog:(id<DypayIRISLog> _Nonnull)log;
- (nonnull NSString *)stringUsingDefaultFormatter:(nonnull id<DypayIRISLog>)log;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,27 @@
//
// DypayDIRSMMapCache.h
// DypayDataIRIS
//
// Created by ByteDance on 2024/3/11.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSMMapCache : NSObject
@property (nonatomic, assign, readonly) BOOL isMapping;
@property (nonatomic, assign, readonly, nullable) void *object;
- (instancetype)initWithPath:(NSString *)path;
- (BOOL)mmap:(size_t)size;
- (void)munmap;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,54 @@
//
// DypayDIRSModuleHive.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/12.
//
#import <Foundation/Foundation.h>
#import "DypayIRISInterfaceDefines.h"
#import "DypayDIRSConcurrentCollection.h"
NS_ASSUME_NONNULL_BEGIN
@class DypayDIRSContext;
@interface DypayDIRSModuleHive : NSObject {
}
@property (nonatomic, weak) DypayDIRSContext* context;
- (instancetype)initWithContext:(nonnull DypayDIRSContext *)context;
- (void)resume;
- (void)suspend;
- (void)start;
- (nullable id<DypayIRISModule>)loadUsingId:(NSString *)moduleId;
- (nullable id<DypayIRISModule>)loadUsingClass:(Class<DypayIRISModule>)moduleClass;
- (nullable NSArray *)loadUsingProtocol:(Protocol *)protocol;
- (void)notify:(nonnull Protocol *)protocol
selector:(SEL)sel
arguments:(NSArray * _Nullable)arguments;
- (BOOL)handleURL:(nonnull NSURL *)url;
- (void)raiseError:(nonnull NSError *)error
isFatal:(BOOL)fatal
withUserInfo:(nullable id)userInfo;
- (nullable NSDictionary *)exportCommonParameters:(nullable NSArray *)required;
- (nullable NSDictionary *)exportFeatureParameters;
- (nullable NSDictionary *)exportFeatureOptions;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,49 @@
//
// DypayDIRSNetworking.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/18.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSNetworkRequestOptions: NSObject<DypayIRISNetworkRequestOptions>
@property (nonatomic, assign) NSUInteger attempts;
@property (nonatomic, assign) NSTimeInterval timeout;
@property (nullable, nonatomic) NSArray<id<DypayIRISDataCoder>> *compressors;
@property (nullable, nonatomic, weak) id<DypayIRISDataCoder> encryptor;
@property (nullable, nonatomic, weak) id<DypayIRISDataCoder> decryptor;
@property (nullable, nonatomic) NSDictionary *userInfo;
@end
@interface DypayDIRSNetworking : DypayDIRSBasicModule {
}
@property (nonatomic) id<DypayIRISNetworkProvider> provider;
- (void)syncUsingSchema:(nonnull id<DypayIRISServiceSchema>)schema
header:(nullable NSDictionary *)header
body:(nullable id)body
options:(nullable id<DypayIRISNetworkRequestOptions>)options
completion:(void (^_Nullable)(BOOL success, id _Nullable data, id _Nullable response, NSError * _Nullable error, id _Nullable metrics))completionHandler;
- (void)asyncUsingSchema:(nonnull id<DypayIRISServiceSchema>)schema
header:(nullable NSDictionary *)header
body:(nullable id)body
options:(nullable id<DypayIRISNetworkRequestOptions>)options
completion:(void (^_Nullable)(BOOL success, id _Nullable data, id _Nullable response, NSError * _Nullable error, id _Nullable metrics))completionHandler;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,16 @@
//
// DypayDIRSPreStorePlugin.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/10/23.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSPreStorePlugin : DypayDIRSBasicModule
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,16 @@
//
// DypayDIRSRealtimeEventPlugin.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/8/11.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSRealtimeEventPlugin : DypayDIRSBasicModule
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,16 @@
//
// DypayDIRSRemoteSettings.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/8/4.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSRemoteSettings : DypayDIRSBasicModule
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,16 @@
//
// DypayDIRSRemoteSettingsSchema.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/8/4.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSRemoteSettingsSchema : DypayDIRSBasicModule<DypayIRISServiceSchema, DypayIRISModuleGlobal>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,22 @@
//
// DypayDIRSRequestParameters.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/8/4.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class DypayDIRSContext;
@interface DypayDIRSRequestParameters : NSObject
+ (nullable NSDictionary *)commonParameters:(NSUInteger)service
context:(nonnull DypayDIRSContext *)context
fieldKeys:(nullable NSArray *)keys;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,20 @@
//
// DypayDIRSStore.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/13.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSStore : DypayDIRSBasicModule
- (id<DypayIRISStore>)cache;
- (_Nullable id<DypayIRISStore>)preferences;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,22 @@
//
// DypayDIRSTask.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/12.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSTask : NSObject
+ (void)asyncConcurrentTask:(dispatch_block_t)task;
+ (void)asyncGlobalTask:(dispatch_block_t)task;
+ (void)asyncMainTask:(dispatch_block_t)task
forContext:(id)context;
+ (dispatch_queue_t)defaultConcurrent;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,16 @@
//
// DypayDIRSThrottlterPlugin.h
// Pods
//
// Created by ByteDance on 2023/8/4.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSThrottlterPlugin : DypayDIRSBasicModule
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,30 @@
//
// DypayDIRSTracker+Session.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/9/20.
//
#import "DypayDataIRIS.h"
typedef NS_ENUM(NSUInteger, DypayIRISLaunchType) {
DypayIRISLaunchTypeInitialState = 0,
DypayIRISLaunchTypeUserClick,
DypayIRISLaunchTypeRemotePush,
DypayIRISLaunchTypeWidget,
DypayIRISLaunchTypeSpotlight,
DypayIRISLaunchTypeExternal,
DypayIRISLaunchTypeBackground,
DypayIRISLaunchTypeSiri,
DypayIRISLaunchTypeUserLoginChanged = 99,
};
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSTracker (Session)
@property (nonatomic, assign) DypayIRISLaunchType launchType;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,79 @@
//
// DypayDIRSTracker.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/12.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class DypayDIRSConfig,DypayDIRSEventUploadFilterOptions;
@interface DypayDIRSTracker : NSObject
+ (instancetype _Nonnull)mainTracker;
+ (instancetype _Nonnull)initMainTrackerWithConfig:(DypayDIRSConfig * _Nonnull)config;
- (instancetype _Nonnull)initWithConfig:(DypayDIRSConfig * _Nonnull)config;
- (BOOL)start;
- (void)stop;
- (void)setDeviceIdentifiers:(nonnull NSDictionary *)IDs;
- (void)setUserIdentifiers:(nonnull NSDictionary *)IDs;
- (nullable NSString *)clientId;
@end
@interface DypayDIRSTracker (Event)
//Default is YES;
@property (nonatomic, assign) BOOL eventTrackEnabled;
//Default is YES;
@property (nonatomic, assign) BOOL eventUploadEnabled;
- (void)trackEvent:(NSString * _Nonnull)key
withProperties:(NSDictionary * _Nullable)properties;
- (void)trackJSON:(NSDictionary * _Nonnull)json
withType:(NSString * _Nonnull)type;
- (void)addGlobalProperties:(nullable NSDictionary *)properties;
- (void)removeGlobalPropertiesForKeys:(nullable NSArray *)keys;
- (void)removeAllEvents;
@end
@interface DypayDIRSTracker (Enviroment)
- (void)setAppRegion:(nullable NSString *)appRegion;
- (void)setAppLanguage:(nullable NSString *)appLauguage;
- (void)setEventRegion:(nullable NSString *)region;
- (nullable NSString *)currentEventRegion;
@end
@interface DypayDIRSTracker (URL)
- (BOOL)handleURL:(nonnull NSURL *)url;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,32 @@
//
// DypayDIRSUtilities.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/11.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSUtilities : NSObject
+ (nonnull NSString *)rootDirectory;
+ (nullable NSString *)ensureDirectory:(nonnull NSString *)path;
//Runtime
+ (NSString *)timeParser:(NSTimeInterval)time;
+ (NSString *)dateParser:(NSTimeInterval)time;
+ (void)measureExecution:(void (^)(void))execution
completion:(void (^ __nullable)(NSTimeInterval interval))completion;
//equal
+ (BOOL)isObject:(id)obj isEqualTo:(id)target;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,21 @@
//
// DypayDIRSValue.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/11.
//
#import <Foundation/Foundation.h>
#import "DypayIRISInterfaceDefines.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSValue : NSObject<DypayIRISValue>
- (instancetype)initWithValue:(nullable id)object
withSource:(DypayIRISValueSource)source;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,17 @@
//
// DypayDataIRIS.h
// Pods
//
// Created by ByteDance on 2023/7/12.
//
#ifndef DypayDataIRIS_h
#define DypayDataIRIS_h
#import "DypayIRISDefines.h"
#import "DypayDIRSConfig.h"
#import "DypayDIRSTracker.h"
#import "DypayDIRSEndpointConfiguration.h"
#endif /* DypayDataIRIS_h */
@@ -0,0 +1,12 @@
//
// DypayDataIRISDefaultSchema.h
// Pods
//
// Created by ByteDance on 2023/9/14.
//
#ifndef DypayDataIRISDefaultSchema_h
#define DypayDataIRISDefaultSchema_h
#endif /* DypayDataIRISDefaultSchema_h */
@@ -0,0 +1,12 @@
//
// DypayDataIRISEvent.h
// Pods
//
// Created by ByteDance on 2023/9/14.
//
#ifndef DypayDataIRISEvent_h
#define DypayDataIRISEvent_h
#endif /* DypayDataIRISEvent_h */
@@ -0,0 +1,12 @@
//
// DypayDataIRISFMDB.h
// Pods
//
// Created by ByteDance on 2023/9/14.
//
#ifndef DypayDataIRISFMDB_h
#define DypayDataIRISFMDB_h
#endif /* DypayDataIRISFMDB_h */
@@ -0,0 +1,12 @@
//
// DypayDataIRISRemoteSettings.h
// Pods
//
// Created by ByteDance on 2023/9/14.
//
#ifndef DypayDataIRISRemoteSettings_h
#define DypayDataIRISRemoteSettings_h
#endif /* DypayDataIRISRemoteSettings_h */
@@ -0,0 +1,12 @@
//
// DypayDataIRISThrottlter.h
// Pods
//
// Created by ByteDance on 2023/9/14.
//
#ifndef DypayDataIRISThrottlter_h
#define DypayDataIRISThrottlter_h
#endif /* DypayDataIRISThrottlter_h */
@@ -0,0 +1,120 @@
//
// IRSDefines.h
//
//
// Created by ByteDance on 2023/7/11.
//
#ifndef IRSDefines_h
#define IRSDefines_h
typedef NSString * DypayIRISParameterKey;
typedef NSString * DypayIRISOptionsKey;
typedef NSUInteger DypayIRISServiceType;
typedef NS_ENUM(NSInteger, DypayIRISLOG_LEVEL) {
DypayIRISLOG_LEVEL_OFF = 0,
DypayIRISLOG_LEVEL_ERROR = 1,
DypayIRISLOG_LEVEL_WARN = 2,
DypayIRISLOG_LEVEL_INFO = 3,
DypayIRISLOG_LEVEL_DEBUG = 4,
};
typedef NS_ENUM(NSInteger, DypayIRISValueSource) {
DypayIRISValueSourceDefault = 1,
DypayIRISValueSourceLocal,
DypayIRISValueSourceRemote
};
typedef NS_ENUM(NSInteger, DypayIRISEventPacketStrategy) {
DypayIRISEventPacketStrategyDefault = 0,
DypayIRISEventPacketStrategyByteLimitation = 1,
};
FOUNDATION_EXPORT DypayIRISServiceType DypayIRISServiceTypeRemoteSettings;
FOUNDATION_EXPORT DypayIRISServiceType DypayIRISServiceTypeEvent;
FOUNDATION_EXPORT DypayIRISServiceType DypayIRISServiceTypeEventRealtime;
FOUNDATION_EXPORT DypayIRISOptionsKey _Nonnull DypayIRISBatchFilterAllowRegionListKey;
FOUNDATION_EXPORT DypayIRISOptionsKey _Nonnull DypayIRISBatchOptionsMaxConcurrentCountKey;
@protocol DypayIRISLog <NSObject>
@property (nonatomic) DypayIRISLOG_LEVEL level;
@property (nonatomic) NSTimeInterval time;
@property (nullable, nonatomic, copy) NSString * tag;
@property (nullable, nonatomic, copy) NSString * message;
@end
@protocol DypayIRISValue <NSObject>
- (DypayIRISValueSource)source;
- (nullable id)rawValue;
- (nullable NSString *)stringValue;
- (NSInteger)integerValue;
- (double)doubleValue;
- (nullable NSDictionary *)dictioanryValue;
- (nullable NSArray *)arrayValue;
- (BOOL)boolValue;
@end
@protocol DypayIRISEvent <NSObject>
@property (nullable, nonatomic, copy) NSString * key;
@property (nullable, nonatomic, copy) NSString * type;
@property (readonly, nonatomic) NSTimeInterval time;
@property (nonatomic, assign) int64_t index;
@property (nullable, nonatomic, copy) NSNumber* dbIndex;
@property (nullable, nonatomic, copy) NSString* logID;
@property (nullable, nonatomic) NSDictionary * properties;
@property (readonly) NSInteger dataLength;
@property (nullable, readonly) NSString * sessionId;
@property (nullable, readonly) id objectValue;
@end
@protocol DypayIRISEndpoint <NSObject>
@optional
- (id _Nullable)domainForService:(NSUInteger)service
context:(id _Nullable)context;
- (id _Nullable)endpointForService:(NSUInteger)service
context:(id _Nullable)context;
@end
#endif /* IRSDefines_h */
@@ -0,0 +1,99 @@
//
// DypayIRISDefinesPrivate.h
// Pods
//
// Created by ByteDance on 2023/7/12.
//
#ifndef DypayIRISDefinesPrivate_h
#define DypayIRISDefinesPrivate_h
#import "DypayDataIRIS.h"
#import "DypayIRISInterfaceDefines.h"
#import "DypayDIRSContext.h"
#import "DypayDIRSLogger.h"
#import "DypayDIRSStore.h"
#import "DypayIRISMacro.h"
#import "IRSLOG.h"
#import "DypayDIRSEventBatchDispatcher.h"
#import "DypayDIRSNetworking.h"
#import "DypayDIRSIdentity.h"
#import "DypayDIRSExtension.h"
#import "DypayDIRSValue.h"
#import "DypayDIRSEvent.h"
#import "DypayDIRSTask.h"
#import "DypayDIRSBasicFeatureOptions.h"
#import "DypayDIRSRequestParameters.h"
FOUNDATION_EXPORT DypayIRISOptionsKey _Nonnull DypayIRISSentryOptionsAppendCachedEventsKey;
FOUNDATION_EXPORT DypayIRISOptionsKey _Nonnull DypayIRISSentryOptionsAggregatedKey;
FOUNDATION_EXPORT DypayIRISOptionsKey _Nonnull DypayIRISSentryOptionsAggregationConfigurationKey;
FOUNDATION_EXPORT DypayIRISOptionsKey _Nonnull DypayIRISSentryOptionsAggregationDimsKey;
FOUNDATION_EXPORT DypayIRISOptionsKey _Nonnull DypayIRISEnviromentEventRegionKey;
FOUNDATION_EXPORT DypayIRISOptionsKey _Nonnull DypayIRISBatchOptionsEnforceKey;
FOUNDATION_EXPORT DypayIRISOptionsKey _Nonnull DypayIRISBatchOptionsEventStainedKey;
FOUNDATION_EXPORT DypayIRISOptionsKey _Nonnull DypayIRISBatchOptionsConcurrentModeKey;
//append current cached events count
@interface DypayDIRSComplianceConfiguration (Private)
@property (nullable, nonatomic, weak) DypayDIRSConfig *base;
@end
@interface DypayDIRSEventConfiguration (Private)
@property (nullable, nonatomic, weak) DypayDIRSConfig *base;
@end
@interface DypayDIRSContext (Private)
@property (nullable, nonatomic, weak) DypayDIRSLogger *logger;
@property (nullable, nonatomic, weak) id<DypayIRISTracker> tracker;
@property (nullable, nonatomic, weak) id<DypayIRISEventListener> listener;
@property (nullable, nonatomic, weak) id<DypayIRISSentry> sentry;
@property (nullable, nonatomic, weak) DypayDIRSIdentity *identity;
@property (nullable, nonatomic, weak) DypayDIRSEventBatchDispatcher* dispatcher;
@property (nullable, nonatomic, weak) DypayDIRSStore *store;
@property (nullable, nonatomic, weak) DypayDIRSNetworking *networking;
@property (nullable, nonatomic, weak) DypayDIRSBasicFeatureOptions *basicFeatureOptions;
@property (nullable, nonatomic, weak) id samplingModule;
@end
@interface DypayDIRSTracker (Private)
- (nonnull DypayDIRSContext *)context;
@end
@interface DypayDIRSConfig (Private)
- (BOOL)registerModule:(nullable Class<DypayIRISModule>)moduleClass;
- (void)unregisterModule:(nullable Class)moduleClass;
- (nonnull NSArray<Class<DypayIRISModule>> *)registeredModules;
- (void)disableModule:(nonnull NSString *)moduleId;
- (nonnull NSArray<NSString *> *)disabledModuleIds;
- (nullable NSString *)uniqueKey;
@end
#endif /* DypayIRISDefinesPrivate_h */
@@ -0,0 +1,556 @@
//
// IRSInterfaceDefines.h
// Pods
//
// Created by ByteDance on 2023/7/11.
//
#ifndef IRSInterfaceDefines_h
#define IRSInterfaceDefines_h
#import "DypayIRISDefines.h"
@class DypayDIRSContext,DypayDIRSValue;
#define DypayIRIS_MODULE_PRIORITY_HIGH 99
#define DypayIRIS_MODULE_PRIORITY_DEFAULT 50
#define DypayIRIS_MODULE_PRIORITY_LOW 0
#define DypayIRIS_MODULE_PRIORITY_CONFIG DypayIRIS_MODULE_PRIORITY_HIGH + 1
#define DypayIRIS_MODULE_PRIORITY_EVENT (DypayIRIS_MODULE_PRIORITY_DEFAULT + 1)
typedef NS_ENUM(NSInteger, DypayIRISState) {
DypayIRISStateDefault = 0,
DypayIRISStateRunning,
DypayIRISStateSuspending
};
typedef NS_ENUM(NSInteger, DypayIRISPriority) {
DypayIRISPriorityRealtime = (-99),
DypayIRISPriorityDefault = 0,
};
typedef NS_ENUM(NSInteger, DypayIRISBatchTrigger) {
DypayIRISBatchTriggerTimer = 1 << 0, //1
DypayIRISBatchTriggerEnterBackground = 1 << 1, //2
DypayIRISBatchTriggerRealtime = 1 << 2, //4
DypayIRISBatchTriggerLaunch = 1 << 3, //8
DypayIRISBatchTriggerFlush = 1 << 4, //16
};
typedef NS_ENUM(NSInteger, DypayIRISEventPackResult) {
DypayIRISEventPackResultAvalible = 0,
DypayIRISEventPackResultFull = 1,
DypayIRISEventPackResultInvalid = 2
};
@class DypayDIRSConfig;
@protocol DypayIRISModule <NSObject>
+ (nonnull NSString *)moduleId;
+ (nonnull NSString *)moduleVersion;
+ (BOOL)isPlugin;
+ (NSInteger)priority;
@property BOOL isEnabled;
@property DypayIRISState state;
@property (nullable, readonly) DypayDIRSContext *context;
@property (nullable, nonatomic, copy) NSString* category;
- (instancetype _Nonnull )initWithContext:(DypayDIRSContext * _Nonnull)context;
- (nullable dispatch_queue_t)executionQueue;
- (void)commonInit;
- (void)resume;
- (void)suspend;
@optional
+ (nonnull NSArray *)moduleDependencies;
- (void)waitUtilDone;
@end
@protocol DypayIRISModuleGlobal <DypayIRISModule>
@required
+ (nonnull instancetype)sharedInstance;
@end
@protocol DypayIRISApplicationObserver <DypayIRISModule>
@optional
- (void)onApplicationDidFinishLaunching;
- (void)onApplicationDidBecomeActive;
- (void)onApplicationWillEnterForeground;
- (void)onApplicationWillResignActive;
- (void)onApplicationDidEnterBackground;
- (void)onApplicationWillTerminate;
- (void)onApplicationDidReceiveMemoryWarning;
@end
@protocol DypayIRISContextObserver <DypayIRISModule>
@optional
- (void)onFinishInitialization:(nonnull DypayDIRSContext *)context;
- (void)onFinishLaunching:(nonnull DypayDIRSContext *)context;
@end
@protocol DypayIRISIdentifierObserver <DypayIRISModule>
@optional
- (void)onDeviceIdentifiersChanged:(nonnull NSDictionary *)change;
- (void)onUserIdentifiersChanged:(nonnull NSDictionary *)change;
- (void)onIdentifierAvailable;
@end
@protocol DypayIRISSessionObserver <NSObject>
@optional
- (void)onSessionLaunch:(nonnull NSString *)sessionId;
- (void)onSessionTerminate:(nonnull NSString *)sessionId;
@end
@protocol DypayIRISEventSerializer <NSObject>
- (nullable NSData *)dataWithEvent:(nullable id)event options:(nullable id)opt error:(NSError * _Nullable * _Nullable)error;
- (nullable id)eventWithData:(nullable NSData *)data options:(nullable id)opt error:(NSError * _Nullable * _Nullable)error;
- (nullable id)eventWithDictionary:(nullable NSDictionary *)dict options:(nullable id)opt error:(NSError * _Nullable * _Nullable)error;
- (NSUInteger)encodingType;
+ (nullable NSArray *)allowedParameterFields;
@end
@protocol DypayIRISEventStore <DypayIRISModule>
- (void)addEvent:(id _Nonnull )event;
- (void)removeEvents:(id _Nullable )batchOpts;
- (void)queryEvents:(id _Nullable)batchOpts
usingBlock:(nonnull void (^)(BOOL finish, id _Nullable event , BOOL * _Nonnull stop))block;
@property (nullable, nonatomic, weak) id<DypayIRISEventSerializer> serializer;
@optional
- (BOOL)startWithPath:(nonnull NSString *)path;
- (void)reset;
- (nullable id)executeStatement:(nonnull NSString *)sql;
@end
@protocol DypayIRISTracker <DypayIRISModule>
@required
@property (nullable, readonly) id<DypayIRISEventStore> store;
- (void)setEnviromentVar:(nonnull id)val forKey:(nonnull NSString *)key;
- (nullable id)enviromentVarForKey:(nonnull NSString *)key;
- (void)trackEvent:(id<DypayIRISEvent> _Nonnull)event;
- (void)addGlobalProperties:(NSDictionary *_Nonnull)properties;
- (void)removeGlobalPropertieKeys:(NSArray *_Nonnull)keys;
- (void)removeAllEvents;
@optional
- (void)addCommonParameters:(NSDictionary *_Nonnull)parameters;
- (void)configureUsingBlock:(nonnull dispatch_block_t)block;
@end
@protocol DypayIRISEventProcedureHandler <DypayIRISModule>
- (BOOL)handleProcedure:(id<DypayIRISEvent> _Nonnull)event
withError:(NSError * _Nullable __autoreleasing *_Nullable)error;
@end
@protocol DypayIRISEventPreProcedureHandler <DypayIRISModule>
- (BOOL)prehandleProcedure:(id<DypayIRISEvent> _Nonnull)event
withError:(NSError * _Nullable __autoreleasing *_Nullable)error;
@end
@protocol DypayIRISEventListener <DypayIRISModule>
- (void)notifyEventsAccepted:(nonnull NSArray *)events
withOptions:(nullable id)opt;
- (void)notifyEventsStored:(nonnull NSArray *)events
withOptions:(nullable id)opt;;
- (void)notifyEventsDropped:(nonnull NSArray *)events
withOptions:(nullable id)opt
withError:(NSError *_Nullable)error;
- (void)notifyEventsUploaded:(nonnull NSArray *)events
withOptions:(nullable id)opt;
@end
@protocol DypayIRISEventObserver <DypayIRISModule>
@optional
- (void)onEventAccepted:(id<DypayIRISEvent> _Nonnull)evt;
- (void)onEventStored:(id<DypayIRISEvent> _Nonnull)evt;
- (void)onEventDropped:(id<DypayIRISEvent> _Nonnull)evt withError:(NSError *_Nullable)error;
- (void)onEventUploaded:(id<DypayIRISEvent> _Nonnull)evt;
@end
@protocol DypayIRISEventPacker <DypayIRISModule>
@property (nonatomic, assign) NSUInteger maxPackLength;
@property (nonatomic, assign) NSUInteger maxEventCount;
@property (nonatomic, assign) DypayIRISEventPacketStrategy strategy;
- (DypayIRISEventPackResult)appendEvent:(nullable id<DypayIRISEvent>)event;
- (nonnull NSData *)serializedData;
- (nonnull id)objectValue;
- (nonnull NSArray *)eventIDs;
- (nonnull NSArray<id<DypayIRISEvent>> *)packetEvents;
@optional
- (void)appendCommonParameters:(nullable NSDictionary *)parameters;
- (void)appendFeatureParameters:(nullable NSDictionary *)features;
- (void)appendFeatureOptions:(nullable NSDictionary *)options;
@end
@protocol DypayIRISThrottlter <DypayIRISModule>
- (void)configure:(nullable id)strategy;
- (BOOL)allowed:(nullable id)options
reason:(NSError * _Nullable __autoreleasing *_Nullable)reason;
- (void)setBasicInterval:(NSTimeInterval)interval;
- (NSTimeInterval)adjustedInterval;
- (void)adjust:(nonnull id)result;
@end
@protocol DypayIRISURLHandler <DypayIRISModule>
- (BOOL)handleURL:(NSURL *_Nonnull)url;
@end
@protocol DypayIRISDataCoder <DypayIRISModule>
- (nonnull NSString *)algorithm;
@optional
- (nullable NSDictionary *)requiredHTTPHeaderFields;
- (nullable NSDictionary *)requiredParameters;
- (nullable NSData *)encodedData:(NSData *_Nonnull)input
options:(nullable id)options
error:(NSError * _Nullable * _Nullable)error;
- (nullable NSData *)decodedData:(nonnull NSData *)input
options:(nullable id)options
error:(NSError * _Nullable * _Nullable)error;
- (uint64_t)hashUsingData:(nonnull id)input;
- (void)setOptions:(nullable NSDictionary *)options;
@end
@protocol DypayIRISTimer <NSObject>
@required
@property NSTimeInterval tickTime;
- (NSTimeInterval)timerInterval;
- (void)onTimerTick;
@end
@protocol DypayIRISLogger <NSObject>
- (void)addLog:(nonnull id<DypayIRISLog>)log;
@end
@protocol DypayIRISErrorHandler <DypayIRISModule>
@required
- (void)onError:(NSError *_Nonnull)error;
@end
@protocol DypayIRISStore <NSObject>
- (nullable id)objectForKey:(NSString * _Nonnull)key;
- (BOOL)setObject:(id _Nonnull)object
forKey:(NSString * _Nonnull)key;
- (BOOL)removeObjectForKey:(NSString * _Nonnull)key;
@end
@protocol DypayIRISNetworkRequestOptions <DypayIRISModule>
@property (nonatomic, assign) NSUInteger attempts;
@property (nonatomic, assign) NSTimeInterval timeout;
@property (nullable, nonatomic, strong) NSArray* compressors;
@property (nullable, nonatomic, weak) id<DypayIRISDataCoder> encryptor;
@property (nullable, nonatomic, weak) id<DypayIRISDataCoder> decryptor;
@property (nullable, nonatomic) NSDictionary *userInfo;
@end
@protocol DypayIRISNetworkProvider <DypayIRISModule>
- (void)request:(nonnull NSString *)HTTPUrl
method:(nonnull NSString *)HTTPMethod
headerFields:(nonnull NSDictionary<NSString *,NSString *> *)headerFields
body:(nullable id)body
options:(nullable id)options
completion:(nonnull void (^)(id _Nullable data, id _Nullable response, NSError * _Nullable error))completion;
@end
@protocol DypayIRISServiceSchema <DypayIRISModule>
- (BOOL)resultWithResponse:(nullable id)object;
- (id _Nullable)responseObjectWithData:(nonnull NSData *)data;
/*
* should start with '/'
*/
- (NSString *_Nonnull)HTTPPath;
/*
* GET/POST/PUT...
*/
- (NSString * _Nonnull)HTTPMethod;
- (nullable id)HTTPBody:(nonnull DypayDIRSContext *)context
options:(nullable id<DypayIRISNetworkRequestOptions>)options;
- (NSUInteger)serviceType;
@optional
- (NSDictionary * _Nullable)HTTPHeaderFields;
- (nullable NSString *)getLogID:(nonnull NSHTTPURLResponse *)response;
- (NSString * _Nullable)enchantURL:(NSString * _Nonnull)url;
- (nullable id)HTTPBodyPacker:(nonnull DypayDIRSContext *)context;
@end
@protocol DypayIRISEventUploadExecutor <DypayIRISModule>
@property (nonatomic, assign) NSTimeInterval interval;
@property (nullable, nonatomic, weak) id<DypayIRISServiceSchema> serializer;
@property (nullable, nonatomic) NSArray<id<DypayIRISDataCoder>> *compressors;
@property (nullable, nonatomic, weak) id<DypayIRISDataCoder> encryptor;
@property (nullable, nonatomic, weak) id<DypayIRISDataCoder> decryptor;
@property (nullable, nonatomic, weak) id<DypayIRISEventStore> eventStore;
@property (nullable, nonatomic) id<DypayIRISThrottlter> throttlter;
@property (nonatomic, assign) DypayIRISPriority priority;
@property (nonatomic, assign) DypayIRISState execState;
@property (nullable, nonatomic) NSDictionary *options;
- (void)executeUpload:(DypayIRISBatchTrigger)trigger;
- (void)executeUpload:(DypayIRISBatchTrigger)trigger
options:(nullable NSDictionary *)options;
@end
@protocol DypayIRISEventRealtimeHandler <DypayIRISModule>
- (void)onRealtimeEventRecieved;
@end
@protocol DypayIRISParameterHandler <DypayIRISModule>
@optional
- (nullable NSArray *)supportedParameterKeys;
- (nullable id)parameterForKey:(nonnull NSString *)key;
- (NSDictionary * _Nullable)exportParameters:(nullable NSArray *)required;
- (NSDictionary * _Nullable)exportFeatureParameters;
- (NSDictionary * _Nullable)exportFeatureOptions;
@end
@protocol DypayIRISConfigurationHandler
@property (nullable, readonly) DypayDIRSValue *config;
@optional
- (void)restore;
@end
@protocol DypayIRISConfigurationObserver
@optional
- (void)onRemoteSettingsDidUpdate:(nonnull DypayDIRSValue *)config;
- (void)onRealtimeSettingsDidUpdate:(nonnull DypayDIRSValue *)config;
@end
@protocol DypayIRISSentry <DypayIRISModule>
//default schema
- (void)monitoring:(nonnull NSString *)key
dimensions:(nullable NSDictionary *)dimensions
options:(nullable NSDictionary *)options;
@end
#endif /* IRSInterfaceDefines_h */
@@ -0,0 +1,136 @@
//
// DypayIRISMacro.h
// Pods
//
// Created by ByteDance on 2023/7/11.
//
#ifndef DypayIRISMacro_h
#define DypayIRISMacro_h
#include "metamacros.h"
#define DypayIRIS_CONCAT(A, B) A##B
#define DypayIRIS_EXPORT_MODULE(module_id, module_version) \
+ (NSString *)moduleId { return module_id; } \
+ (NSString *)moduleVersion { return module_version; }
#define DypayIRIS_EXPORT_PLUGIN(module_id, module_version) \
+ (NSString *)moduleId { return module_id; } \
+ (NSString *)moduleVersion { return module_version; } \
+ (BOOL)isPlugin { return YES; }
#define DypayIRIS_EXPORT_PARAMETER(field, returnType) \
- (returnType)DypayIRIS_CONCAT(__datairis_parameter__, field)
/*
* Define SharedInstance Implementation
*
* SHARED_INSTANCE_IMPL(sharedManager)
* Equals
* + (instancetype)sharedManager {...}
*/
#undef EXPORT_SHARED_INSTANCE
#define EXPORT_SHARED_INSTANCE(sharedInstanceMethod) \
+ (instancetype)sharedInstanceMethod \
{ \
static dispatch_once_t once; \
static id __singleton__; \
dispatch_once( &once, ^{ \
__singleton__ = [[self alloc] init]; \
if ([__singleton__ respondsToSelector:@selector(commonInit)]) { \
[__singleton__ performSelector:@selector(commonInit)]; \
}\
}); \
return __singleton__; \
} \
/*
* Usage paired @weakify(self) & @strongify(self)
*/
#ifndef weakify
#if DEBUG
#if __has_feature(objc_arc)
#define weakify(object) autoreleasepool{} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) autoreleasepool{} __block __typeof__(object) block##_##object = object;
#endif
#else
#if __has_feature(objc_arc)
#define weakify(object) try{} @finally{} {} __weak __typeof__(object) weak##_##object = object;
#else
#define weakify(object) try{} @finally{} {} __block __typeof__(object) block##_##object = object;
#endif
#endif
#endif
#ifndef strongify
#if DEBUG
#if __has_feature(objc_arc)
#define strongify(object) autoreleasepool{} __typeof__(object) object = weak##_##object;
#else
#define strongify(object) autoreleasepool{} __typeof__(object) object = block##_##object;
#endif
#else
#if __has_feature(objc_arc)
#define strongify(object) try{} @finally{} __typeof__(object) object = weak##_##object;
#else
#define strongify(object) try{} @finally{} __typeof__(object) object = block##_##object;
#endif
#endif
#endif
#ifndef DypayIRIS_keywordify
#if DEBUG
#define DypayIRIS_keywordify autoreleasepool {}
#else
#define DypayIRIS_keywordify try {} @catch (...) {}
#endif
#endif
/*
*
* @onExit {
//code
}
*/
#ifndef onExit
#define onExit \
DypayIRIS_keywordify \
__strong datairis_cleanup_t metamacro_concat(macro_exitBlock_, __LINE__) __attribute__((cleanup(datairis_executeCleanupBlock), unused)) = ^
typedef void (^datairis_cleanup_t)(void);
static inline void datairis_executeCleanupBlock (__strong datairis_cleanup_t *block) {
(*block)();
}
#endif
/*
* {
* @lock_guard(lock)
* //mutex excution
* }
*/
#ifndef lock_guard
#define lock_guard(l) \
DypayIRIS_keywordify \
[l lock]; \
@onExit { \
[l unlock]; \
};
#endif
#endif /* DypayIRISMacro_h */
@@ -0,0 +1,74 @@
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif
#import "DypayAPI.h"
#import "DypayDIRSApplication.h"
#import "DypayDIRSBasicFeatureOptions.h"
#import "DypayDIRSCompressionGzipPlugin.h"
#import "DypayDIRSContext.h"
#import "DypayDIRSEnviroment.h"
#import "DypayDIRSGlobalTimer.h"
#import "DypayDIRSStore.h"
#import "DypayDIRSValue.h"
#import "DypayIRISDefinesPrivate.h"
#import "DypayDIRSIdentity.h"
#import "DypayDIRSLogger.h"
#import "IRSLOG.h"
#import "DypayDIRSBasicModule.h"
#import "DypayDIRSModuleHive.h"
#import "DypayDIRSNetworking.h"
#import "DypayDIRSRequestParameters.h"
#import "DypayDataIRIS.h"
#import "DypayDIRSConfig.h"
#import "DypayDIRSEndpointConfiguration.h"
#import "DypayDIRSTracker.h"
#import "DypayDIRSConcurrentCollection.h"
#import "DypayDIRSErrorBuilder.h"
#import "DypayDIRSExtension.h"
#import "DypayDIRSMMapCache.h"
#import "DypayDIRSTask.h"
#import "DypayDIRSUtilities.h"
#import "DypayIRISInterfaceDefines.h"
#import "DypayIRISMacro.h"
#import "metamacros.h"
#import "DypayIRISDefines.h"
#import "DypayDIRSEvent.h"
#import "DypayDIRSEventBatchDispatcher.h"
#import "DypayDIRSEventBatchExecutor.h"
#import "DypayDIRSEventEntry.h"
#import "DypayDIRSEventListener.h"
#import "DypayDataIRISEvent.h"
#import "DypayDIRSEventBlockPlugin.h"
#import "DypayDIRSEventPacker.h"
#import "DypayDIRSEventRequestSchema.h"
#import "DypayDIRSEventSerializer.h"
#import "DypayDataIRISDefaultSchema.h"
#import "DIRSFMDB.h"
#import "DypayDIRSEventStore.h"
#import "DypayDIRSFMDatabase.h"
#import "DypayDIRSFMDatabaseQueue.h"
#import "DypayDIRSFMResultSet.h"
#import "DypayDIRSPreStorePlugin.h"
#import "DypayDataIRISFMDB.h"
#import "DypayDIRSEventSession.h"
#import "DypayDIRSTracker+Session.h"
#import "DypayDIRSRealtimeEventPlugin.h"
#import "DypayDIRSRemoteSettings.h"
#import "DypayDataIRISRemoteSettings.h"
#import "DypayDIRSRemoteSettingsSchema.h"
#import "DypayDIRSThrottlterPlugin.h"
#import "DypayDataIRISThrottlter.h"
#import "DypayTrackerManager.h"
FOUNDATION_EXPORT double DypaySDKVersionNumber;
FOUNDATION_EXPORT const unsigned char DypaySDKVersionString[];
@@ -0,0 +1,24 @@
//
// DypayTrackerManager.h
// DypaySDK-CJPaySandBox
//
// Created by shanghuaijun on 2024/12/19.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class DypayDIRSTracker;
@interface DypayTrackerManager : NSObject
@property (nonatomic, strong, readonly) DypayDIRSTracker *tracker;
+ (instancetype)defaultService;
+ (void)initConfig;
+ (void)event:(NSString *_Nonnull)eventName params:(NSDictionary *_Nullable)params;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,51 @@
//
// IRSLOG.h
// Pods
//
// Created by ByteDance on 2023/7/11.
//
#ifndef IRSLOG_h
#define IRSLOG_h
#ifdef __OBJC__
extern void datairis_log_oc(int level, id ctx, NSString *tag, NSString *,...);
#undef LOG_MACRO
#define LOG_MACRO(flag,ctx,tag,fmt,...) \
if (ctx && ctx.config && ctx.config.logLevel >= flag) { \
datairis_log_oc(flag, ctx, tag, fmt, ##__VA_ARGS__); \
}
#endif
#ifdef DypayIRIS_MINIMUM_VERSION
#define LOG_DEBUG
#define LOG_INFO
#define LOG_WARN
#else
#undef LOG_DEBUG
#define LOG_DEBUG(ctx, tag, fmt, ...) LOG_MACRO(4 ,ctx, tag, fmt, ##__VA_ARGS__)
//#define LOG_DEBUG(ctx, tag, fmt, ...)
#undef LOG_INFO
#define LOG_INFO(ctx, tag, fmt, ...) LOG_MACRO(3 ,ctx, tag, fmt, ##__VA_ARGS__)
//#define LOG_INFO(ctx, tag, fmt, ...)
#undef LOG_WARN
#define LOG_WARN(ctx, tag, fmt, ...) LOG_MACRO(2 ,ctx, tag, fmt, ##__VA_ARGS__)
#endif
#undef LOG_ERROR
#define LOG_ERROR(ctx, tag, fmt, ...) LOG_MACRO(1 ,ctx, tag, fmt, ##__VA_ARGS__)
#endif /* IRSLOG_h */
@@ -0,0 +1,669 @@
/**
* Macros for metaprogramming
* ExtendedC
*
* Copyright (C) 2012 Justin Spahr-Summers
* Released under the MIT license
*/
#ifndef EXTC_METAMACROS_H
#define EXTC_METAMACROS_H
/**
* Executes one or more expressions (which may have a void type, such as a call
* to a function that returns no value) and always returns true.
*/
#define metamacro_exprify(...) \
((__VA_ARGS__), true)
/**
* Returns a string representation of VALUE after full macro expansion.
*/
#define metamacro_stringify(VALUE) \
metamacro_stringify_(VALUE)
/**
* Returns A and B concatenated after full macro expansion.
*/
#define metamacro_concat(A, B) \
metamacro_concat_(A, B)
/**
* Returns the Nth variadic argument (starting from zero). At least
* N + 1 variadic arguments must be given. N must be between zero and twenty,
* inclusive.
*/
#define metamacro_at(N, ...) \
metamacro_concat(metamacro_at, N)(__VA_ARGS__)
/**
* Returns the number of arguments (up to twenty) provided to the macro. At
* least one argument must be provided.
*
* Inspired by P99: http://p99.gforge.inria.fr
*/
#define metamacro_argcount(...) \
metamacro_at(20, __VA_ARGS__, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
/**
* Identical to #metamacro_foreach_cxt, except that no CONTEXT argument is
* given. Only the index and current argument will thus be passed to MACRO.
*/
#define metamacro_foreach(MACRO, SEP, ...) \
metamacro_foreach_cxt(metamacro_foreach_iter, SEP, MACRO, __VA_ARGS__)
/**
* For each consecutive variadic argument (up to twenty), MACRO is passed the
* zero-based index of the current argument, CONTEXT, and then the argument
* itself. The results of adjoining invocations of MACRO are then separated by
* SEP.
*
* Inspired by P99: http://p99.gforge.inria.fr
*/
#define metamacro_foreach_cxt(MACRO, SEP, CONTEXT, ...) \
metamacro_concat(metamacro_foreach_cxt, metamacro_argcount(__VA_ARGS__))(MACRO, SEP, CONTEXT, __VA_ARGS__)
/**
* Identical to #metamacro_foreach_cxt. This can be used when the former would
* fail due to recursive macro expansion.
*/
#define metamacro_foreach_cxt_recursive(MACRO, SEP, CONTEXT, ...) \
metamacro_concat(metamacro_foreach_cxt_recursive, metamacro_argcount(__VA_ARGS__))(MACRO, SEP, CONTEXT, __VA_ARGS__)
/**
* In consecutive order, appends each variadic argument (up to twenty) onto
* BASE. The resulting concatenations are then separated by SEP.
*
* This is primarily useful to manipulate a list of macro invocations into instead
* invoking a different, possibly related macro.
*/
#define metamacro_foreach_concat(BASE, SEP, ...) \
metamacro_foreach_cxt(metamacro_foreach_concat_iter, SEP, BASE, __VA_ARGS__)
/**
* Iterates COUNT times, each time invoking MACRO with the current index
* (starting at zero) and CONTEXT. The results of adjoining invocations of MACRO
* are then separated by SEP.
*
* COUNT must be an integer between zero and twenty, inclusive.
*/
#define metamacro_for_cxt(COUNT, MACRO, SEP, CONTEXT) \
metamacro_concat(metamacro_for_cxt, COUNT)(MACRO, SEP, CONTEXT)
/**
* Returns the first argument given. At least one argument must be provided.
*
* This is useful when implementing a variadic macro, where you may have only
* one variadic argument, but no way to retrieve it (for example, because \c ...
* always needs to match at least one argument).
*
* @code
#define varmacro(...) \
metamacro_head(__VA_ARGS__)
* @endcode
*/
#define metamacro_head(...) \
metamacro_head_(__VA_ARGS__, 0)
/**
* Returns every argument except the first. At least two arguments must be
* provided.
*/
#define metamacro_tail(...) \
metamacro_tail_(__VA_ARGS__)
/**
* Returns the first N (up to twenty) variadic arguments as a new argument list.
* At least N variadic arguments must be provided.
*/
#define metamacro_take(N, ...) \
metamacro_concat(metamacro_take, N)(__VA_ARGS__)
/**
* Removes the first N (up to twenty) variadic arguments from the given argument
* list. At least N variadic arguments must be provided.
*/
#define metamacro_drop(N, ...) \
metamacro_concat(metamacro_drop, N)(__VA_ARGS__)
/**
* Decrements VAL, which must be a number between zero and twenty, inclusive.
*
* This is primarily useful when dealing with indexes and counts in
* metaprogramming.
*/
#define metamacro_dec(VAL) \
metamacro_at(VAL, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19)
/**
* Increments VAL, which must be a number between zero and twenty, inclusive.
*
* This is primarily useful when dealing with indexes and counts in
* metaprogramming.
*/
#define metamacro_inc(VAL) \
metamacro_at(VAL, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21)
/**
* If A is equal to B, the next argument list is expanded; otherwise, the
* argument list after that is expanded. A and B must be numbers between zero
* and twenty, inclusive. Additionally, B must be greater than or equal to A.
*
* @code
// expands to true
metamacro_if_eq(0, 0)(true)(false)
// expands to false
metamacro_if_eq(0, 1)(true)(false)
* @endcode
*
* This is primarily useful when dealing with indexes and counts in
* metaprogramming.
*/
#define metamacro_if_eq(A, B) \
metamacro_concat(metamacro_if_eq, A)(B)
/**
* Identical to #metamacro_if_eq. This can be used when the former would fail
* due to recursive macro expansion.
*/
#define metamacro_if_eq_recursive(A, B) \
metamacro_concat(metamacro_if_eq_recursive, A)(B)
/**
* Returns 1 if N is an even number, or 0 otherwise. N must be between zero and
* twenty, inclusive.
*
* For the purposes of this test, zero is considered even.
*/
#define metamacro_is_even(N) \
metamacro_at(N, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1)
/**
* Returns the logical NOT of B, which must be the number zero or one.
*/
#define metamacro_not(B) \
metamacro_at(B, 1, 0)
// IMPLEMENTATION DETAILS FOLLOW!
// Do not write code that depends on anything below this line.
#define metamacro_stringify_(VALUE) # VALUE
#define metamacro_concat_(A, B) A ## B
#define metamacro_foreach_iter(INDEX, MACRO, ARG) MACRO(INDEX, ARG)
#define metamacro_head_(FIRST, ...) FIRST
#define metamacro_tail_(FIRST, ...) __VA_ARGS__
#define metamacro_consume_(...)
#define metamacro_expand_(...) __VA_ARGS__
// implemented from scratch so that metamacro_concat() doesn't end up nesting
#define metamacro_foreach_concat_iter(INDEX, BASE, ARG) metamacro_foreach_concat_iter_(BASE, ARG)
#define metamacro_foreach_concat_iter_(BASE, ARG) BASE ## ARG
// metamacro_at expansions
#define metamacro_at0(...) metamacro_head(__VA_ARGS__)
#define metamacro_at1(_0, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at2(_0, _1, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at3(_0, _1, _2, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at4(_0, _1, _2, _3, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at5(_0, _1, _2, _3, _4, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at6(_0, _1, _2, _3, _4, _5, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at7(_0, _1, _2, _3, _4, _5, _6, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at8(_0, _1, _2, _3, _4, _5, _6, _7, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at9(_0, _1, _2, _3, _4, _5, _6, _7, _8, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at10(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at11(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at12(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at13(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at14(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at15(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at16(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at17(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at18(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at19(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, ...) metamacro_head(__VA_ARGS__)
#define metamacro_at20(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, ...) metamacro_head(__VA_ARGS__)
// metamacro_foreach_cxt expansions
#define metamacro_foreach_cxt0(MACRO, SEP, CONTEXT)
#define metamacro_foreach_cxt1(MACRO, SEP, CONTEXT, _0) MACRO(0, CONTEXT, _0)
#define metamacro_foreach_cxt2(MACRO, SEP, CONTEXT, _0, _1) \
metamacro_foreach_cxt1(MACRO, SEP, CONTEXT, _0) \
SEP \
MACRO(1, CONTEXT, _1)
#define metamacro_foreach_cxt3(MACRO, SEP, CONTEXT, _0, _1, _2) \
metamacro_foreach_cxt2(MACRO, SEP, CONTEXT, _0, _1) \
SEP \
MACRO(2, CONTEXT, _2)
#define metamacro_foreach_cxt4(MACRO, SEP, CONTEXT, _0, _1, _2, _3) \
metamacro_foreach_cxt3(MACRO, SEP, CONTEXT, _0, _1, _2) \
SEP \
MACRO(3, CONTEXT, _3)
#define metamacro_foreach_cxt5(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4) \
metamacro_foreach_cxt4(MACRO, SEP, CONTEXT, _0, _1, _2, _3) \
SEP \
MACRO(4, CONTEXT, _4)
#define metamacro_foreach_cxt6(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5) \
metamacro_foreach_cxt5(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4) \
SEP \
MACRO(5, CONTEXT, _5)
#define metamacro_foreach_cxt7(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6) \
metamacro_foreach_cxt6(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5) \
SEP \
MACRO(6, CONTEXT, _6)
#define metamacro_foreach_cxt8(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7) \
metamacro_foreach_cxt7(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6) \
SEP \
MACRO(7, CONTEXT, _7)
#define metamacro_foreach_cxt9(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8) \
metamacro_foreach_cxt8(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7) \
SEP \
MACRO(8, CONTEXT, _8)
#define metamacro_foreach_cxt10(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9) \
metamacro_foreach_cxt9(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8) \
SEP \
MACRO(9, CONTEXT, _9)
#define metamacro_foreach_cxt11(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) \
metamacro_foreach_cxt10(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9) \
SEP \
MACRO(10, CONTEXT, _10)
#define metamacro_foreach_cxt12(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11) \
metamacro_foreach_cxt11(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) \
SEP \
MACRO(11, CONTEXT, _11)
#define metamacro_foreach_cxt13(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12) \
metamacro_foreach_cxt12(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11) \
SEP \
MACRO(12, CONTEXT, _12)
#define metamacro_foreach_cxt14(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13) \
metamacro_foreach_cxt13(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12) \
SEP \
MACRO(13, CONTEXT, _13)
#define metamacro_foreach_cxt15(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14) \
metamacro_foreach_cxt14(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13) \
SEP \
MACRO(14, CONTEXT, _14)
#define metamacro_foreach_cxt16(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15) \
metamacro_foreach_cxt15(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14) \
SEP \
MACRO(15, CONTEXT, _15)
#define metamacro_foreach_cxt17(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16) \
metamacro_foreach_cxt16(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15) \
SEP \
MACRO(16, CONTEXT, _16)
#define metamacro_foreach_cxt18(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17) \
metamacro_foreach_cxt17(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16) \
SEP \
MACRO(17, CONTEXT, _17)
#define metamacro_foreach_cxt19(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18) \
metamacro_foreach_cxt18(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17) \
SEP \
MACRO(18, CONTEXT, _18)
#define metamacro_foreach_cxt20(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19) \
metamacro_foreach_cxt19(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18) \
SEP \
MACRO(19, CONTEXT, _19)
// metamacro_foreach_cxt_recursive expansions
#define metamacro_foreach_cxt_recursive0(MACRO, SEP, CONTEXT)
#define metamacro_foreach_cxt_recursive1(MACRO, SEP, CONTEXT, _0) MACRO(0, CONTEXT, _0)
#define metamacro_foreach_cxt_recursive2(MACRO, SEP, CONTEXT, _0, _1) \
metamacro_foreach_cxt_recursive1(MACRO, SEP, CONTEXT, _0) \
SEP \
MACRO(1, CONTEXT, _1)
#define metamacro_foreach_cxt_recursive3(MACRO, SEP, CONTEXT, _0, _1, _2) \
metamacro_foreach_cxt_recursive2(MACRO, SEP, CONTEXT, _0, _1) \
SEP \
MACRO(2, CONTEXT, _2)
#define metamacro_foreach_cxt_recursive4(MACRO, SEP, CONTEXT, _0, _1, _2, _3) \
metamacro_foreach_cxt_recursive3(MACRO, SEP, CONTEXT, _0, _1, _2) \
SEP \
MACRO(3, CONTEXT, _3)
#define metamacro_foreach_cxt_recursive5(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4) \
metamacro_foreach_cxt_recursive4(MACRO, SEP, CONTEXT, _0, _1, _2, _3) \
SEP \
MACRO(4, CONTEXT, _4)
#define metamacro_foreach_cxt_recursive6(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5) \
metamacro_foreach_cxt_recursive5(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4) \
SEP \
MACRO(5, CONTEXT, _5)
#define metamacro_foreach_cxt_recursive7(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6) \
metamacro_foreach_cxt_recursive6(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5) \
SEP \
MACRO(6, CONTEXT, _6)
#define metamacro_foreach_cxt_recursive8(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7) \
metamacro_foreach_cxt_recursive7(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6) \
SEP \
MACRO(7, CONTEXT, _7)
#define metamacro_foreach_cxt_recursive9(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8) \
metamacro_foreach_cxt_recursive8(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7) \
SEP \
MACRO(8, CONTEXT, _8)
#define metamacro_foreach_cxt_recursive10(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9) \
metamacro_foreach_cxt_recursive9(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8) \
SEP \
MACRO(9, CONTEXT, _9)
#define metamacro_foreach_cxt_recursive11(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) \
metamacro_foreach_cxt_recursive10(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9) \
SEP \
MACRO(10, CONTEXT, _10)
#define metamacro_foreach_cxt_recursive12(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11) \
metamacro_foreach_cxt_recursive11(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) \
SEP \
MACRO(11, CONTEXT, _11)
#define metamacro_foreach_cxt_recursive13(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12) \
metamacro_foreach_cxt_recursive12(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11) \
SEP \
MACRO(12, CONTEXT, _12)
#define metamacro_foreach_cxt_recursive14(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13) \
metamacro_foreach_cxt_recursive13(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12) \
SEP \
MACRO(13, CONTEXT, _13)
#define metamacro_foreach_cxt_recursive15(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14) \
metamacro_foreach_cxt_recursive14(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13) \
SEP \
MACRO(14, CONTEXT, _14)
#define metamacro_foreach_cxt_recursive16(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15) \
metamacro_foreach_cxt_recursive15(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14) \
SEP \
MACRO(15, CONTEXT, _15)
#define metamacro_foreach_cxt_recursive17(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16) \
metamacro_foreach_cxt_recursive16(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15) \
SEP \
MACRO(16, CONTEXT, _16)
#define metamacro_foreach_cxt_recursive18(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17) \
metamacro_foreach_cxt_recursive17(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16) \
SEP \
MACRO(17, CONTEXT, _17)
#define metamacro_foreach_cxt_recursive19(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18) \
metamacro_foreach_cxt_recursive18(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17) \
SEP \
MACRO(18, CONTEXT, _18)
#define metamacro_foreach_cxt_recursive20(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19) \
metamacro_foreach_cxt_recursive19(MACRO, SEP, CONTEXT, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18) \
SEP \
MACRO(19, CONTEXT, _19)
// metamacro_for_cxt expansions
#define metamacro_for_cxt0(MACRO, SEP, CONTEXT)
#define metamacro_for_cxt1(MACRO, SEP, CONTEXT) MACRO(0, CONTEXT)
#define metamacro_for_cxt2(MACRO, SEP, CONTEXT) \
metamacro_for_cxt1(MACRO, SEP, CONTEXT) \
SEP \
MACRO(1, CONTEXT)
#define metamacro_for_cxt3(MACRO, SEP, CONTEXT) \
metamacro_for_cxt2(MACRO, SEP, CONTEXT) \
SEP \
MACRO(2, CONTEXT)
#define metamacro_for_cxt4(MACRO, SEP, CONTEXT) \
metamacro_for_cxt3(MACRO, SEP, CONTEXT) \
SEP \
MACRO(3, CONTEXT)
#define metamacro_for_cxt5(MACRO, SEP, CONTEXT) \
metamacro_for_cxt4(MACRO, SEP, CONTEXT) \
SEP \
MACRO(4, CONTEXT)
#define metamacro_for_cxt6(MACRO, SEP, CONTEXT) \
metamacro_for_cxt5(MACRO, SEP, CONTEXT) \
SEP \
MACRO(5, CONTEXT)
#define metamacro_for_cxt7(MACRO, SEP, CONTEXT) \
metamacro_for_cxt6(MACRO, SEP, CONTEXT) \
SEP \
MACRO(6, CONTEXT)
#define metamacro_for_cxt8(MACRO, SEP, CONTEXT) \
metamacro_for_cxt7(MACRO, SEP, CONTEXT) \
SEP \
MACRO(7, CONTEXT)
#define metamacro_for_cxt9(MACRO, SEP, CONTEXT) \
metamacro_for_cxt8(MACRO, SEP, CONTEXT) \
SEP \
MACRO(8, CONTEXT)
#define metamacro_for_cxt10(MACRO, SEP, CONTEXT) \
metamacro_for_cxt9(MACRO, SEP, CONTEXT) \
SEP \
MACRO(9, CONTEXT)
#define metamacro_for_cxt11(MACRO, SEP, CONTEXT) \
metamacro_for_cxt10(MACRO, SEP, CONTEXT) \
SEP \
MACRO(10, CONTEXT)
#define metamacro_for_cxt12(MACRO, SEP, CONTEXT) \
metamacro_for_cxt11(MACRO, SEP, CONTEXT) \
SEP \
MACRO(11, CONTEXT)
#define metamacro_for_cxt13(MACRO, SEP, CONTEXT) \
metamacro_for_cxt12(MACRO, SEP, CONTEXT) \
SEP \
MACRO(12, CONTEXT)
#define metamacro_for_cxt14(MACRO, SEP, CONTEXT) \
metamacro_for_cxt13(MACRO, SEP, CONTEXT) \
SEP \
MACRO(13, CONTEXT)
#define metamacro_for_cxt15(MACRO, SEP, CONTEXT) \
metamacro_for_cxt14(MACRO, SEP, CONTEXT) \
SEP \
MACRO(14, CONTEXT)
#define metamacro_for_cxt16(MACRO, SEP, CONTEXT) \
metamacro_for_cxt15(MACRO, SEP, CONTEXT) \
SEP \
MACRO(15, CONTEXT)
#define metamacro_for_cxt17(MACRO, SEP, CONTEXT) \
metamacro_for_cxt16(MACRO, SEP, CONTEXT) \
SEP \
MACRO(16, CONTEXT)
#define metamacro_for_cxt18(MACRO, SEP, CONTEXT) \
metamacro_for_cxt17(MACRO, SEP, CONTEXT) \
SEP \
MACRO(17, CONTEXT)
#define metamacro_for_cxt19(MACRO, SEP, CONTEXT) \
metamacro_for_cxt18(MACRO, SEP, CONTEXT) \
SEP \
MACRO(18, CONTEXT)
#define metamacro_for_cxt20(MACRO, SEP, CONTEXT) \
metamacro_for_cxt19(MACRO, SEP, CONTEXT) \
SEP \
MACRO(19, CONTEXT)
// metamacro_if_eq expansions
#define metamacro_if_eq0(VALUE) \
metamacro_concat(metamacro_if_eq0_, VALUE)
#define metamacro_if_eq0_0(...) __VA_ARGS__ metamacro_consume_
#define metamacro_if_eq0_1(...) metamacro_expand_
#define metamacro_if_eq0_2(...) metamacro_expand_
#define metamacro_if_eq0_3(...) metamacro_expand_
#define metamacro_if_eq0_4(...) metamacro_expand_
#define metamacro_if_eq0_5(...) metamacro_expand_
#define metamacro_if_eq0_6(...) metamacro_expand_
#define metamacro_if_eq0_7(...) metamacro_expand_
#define metamacro_if_eq0_8(...) metamacro_expand_
#define metamacro_if_eq0_9(...) metamacro_expand_
#define metamacro_if_eq0_10(...) metamacro_expand_
#define metamacro_if_eq0_11(...) metamacro_expand_
#define metamacro_if_eq0_12(...) metamacro_expand_
#define metamacro_if_eq0_13(...) metamacro_expand_
#define metamacro_if_eq0_14(...) metamacro_expand_
#define metamacro_if_eq0_15(...) metamacro_expand_
#define metamacro_if_eq0_16(...) metamacro_expand_
#define metamacro_if_eq0_17(...) metamacro_expand_
#define metamacro_if_eq0_18(...) metamacro_expand_
#define metamacro_if_eq0_19(...) metamacro_expand_
#define metamacro_if_eq0_20(...) metamacro_expand_
#define metamacro_if_eq1(VALUE) metamacro_if_eq0(metamacro_dec(VALUE))
#define metamacro_if_eq2(VALUE) metamacro_if_eq1(metamacro_dec(VALUE))
#define metamacro_if_eq3(VALUE) metamacro_if_eq2(metamacro_dec(VALUE))
#define metamacro_if_eq4(VALUE) metamacro_if_eq3(metamacro_dec(VALUE))
#define metamacro_if_eq5(VALUE) metamacro_if_eq4(metamacro_dec(VALUE))
#define metamacro_if_eq6(VALUE) metamacro_if_eq5(metamacro_dec(VALUE))
#define metamacro_if_eq7(VALUE) metamacro_if_eq6(metamacro_dec(VALUE))
#define metamacro_if_eq8(VALUE) metamacro_if_eq7(metamacro_dec(VALUE))
#define metamacro_if_eq9(VALUE) metamacro_if_eq8(metamacro_dec(VALUE))
#define metamacro_if_eq10(VALUE) metamacro_if_eq9(metamacro_dec(VALUE))
#define metamacro_if_eq11(VALUE) metamacro_if_eq10(metamacro_dec(VALUE))
#define metamacro_if_eq12(VALUE) metamacro_if_eq11(metamacro_dec(VALUE))
#define metamacro_if_eq13(VALUE) metamacro_if_eq12(metamacro_dec(VALUE))
#define metamacro_if_eq14(VALUE) metamacro_if_eq13(metamacro_dec(VALUE))
#define metamacro_if_eq15(VALUE) metamacro_if_eq14(metamacro_dec(VALUE))
#define metamacro_if_eq16(VALUE) metamacro_if_eq15(metamacro_dec(VALUE))
#define metamacro_if_eq17(VALUE) metamacro_if_eq16(metamacro_dec(VALUE))
#define metamacro_if_eq18(VALUE) metamacro_if_eq17(metamacro_dec(VALUE))
#define metamacro_if_eq19(VALUE) metamacro_if_eq18(metamacro_dec(VALUE))
#define metamacro_if_eq20(VALUE) metamacro_if_eq19(metamacro_dec(VALUE))
// metamacro_if_eq_recursive expansions
#define metamacro_if_eq_recursive0(VALUE) \
metamacro_concat(metamacro_if_eq_recursive0_, VALUE)
#define metamacro_if_eq_recursive0_0(...) __VA_ARGS__ metamacro_consume_
#define metamacro_if_eq_recursive0_1(...) metamacro_expand_
#define metamacro_if_eq_recursive0_2(...) metamacro_expand_
#define metamacro_if_eq_recursive0_3(...) metamacro_expand_
#define metamacro_if_eq_recursive0_4(...) metamacro_expand_
#define metamacro_if_eq_recursive0_5(...) metamacro_expand_
#define metamacro_if_eq_recursive0_6(...) metamacro_expand_
#define metamacro_if_eq_recursive0_7(...) metamacro_expand_
#define metamacro_if_eq_recursive0_8(...) metamacro_expand_
#define metamacro_if_eq_recursive0_9(...) metamacro_expand_
#define metamacro_if_eq_recursive0_10(...) metamacro_expand_
#define metamacro_if_eq_recursive0_11(...) metamacro_expand_
#define metamacro_if_eq_recursive0_12(...) metamacro_expand_
#define metamacro_if_eq_recursive0_13(...) metamacro_expand_
#define metamacro_if_eq_recursive0_14(...) metamacro_expand_
#define metamacro_if_eq_recursive0_15(...) metamacro_expand_
#define metamacro_if_eq_recursive0_16(...) metamacro_expand_
#define metamacro_if_eq_recursive0_17(...) metamacro_expand_
#define metamacro_if_eq_recursive0_18(...) metamacro_expand_
#define metamacro_if_eq_recursive0_19(...) metamacro_expand_
#define metamacro_if_eq_recursive0_20(...) metamacro_expand_
#define metamacro_if_eq_recursive1(VALUE) metamacro_if_eq_recursive0(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive2(VALUE) metamacro_if_eq_recursive1(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive3(VALUE) metamacro_if_eq_recursive2(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive4(VALUE) metamacro_if_eq_recursive3(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive5(VALUE) metamacro_if_eq_recursive4(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive6(VALUE) metamacro_if_eq_recursive5(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive7(VALUE) metamacro_if_eq_recursive6(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive8(VALUE) metamacro_if_eq_recursive7(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive9(VALUE) metamacro_if_eq_recursive8(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive10(VALUE) metamacro_if_eq_recursive9(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive11(VALUE) metamacro_if_eq_recursive10(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive12(VALUE) metamacro_if_eq_recursive11(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive13(VALUE) metamacro_if_eq_recursive12(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive14(VALUE) metamacro_if_eq_recursive13(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive15(VALUE) metamacro_if_eq_recursive14(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive16(VALUE) metamacro_if_eq_recursive15(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive17(VALUE) metamacro_if_eq_recursive16(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive18(VALUE) metamacro_if_eq_recursive17(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive19(VALUE) metamacro_if_eq_recursive18(metamacro_dec(VALUE))
#define metamacro_if_eq_recursive20(VALUE) metamacro_if_eq_recursive19(metamacro_dec(VALUE))
// metamacro_take expansions
#define metamacro_take0(...)
#define metamacro_take1(...) metamacro_head(__VA_ARGS__)
#define metamacro_take2(...) metamacro_head(__VA_ARGS__), metamacro_take1(metamacro_tail(__VA_ARGS__))
#define metamacro_take3(...) metamacro_head(__VA_ARGS__), metamacro_take2(metamacro_tail(__VA_ARGS__))
#define metamacro_take4(...) metamacro_head(__VA_ARGS__), metamacro_take3(metamacro_tail(__VA_ARGS__))
#define metamacro_take5(...) metamacro_head(__VA_ARGS__), metamacro_take4(metamacro_tail(__VA_ARGS__))
#define metamacro_take6(...) metamacro_head(__VA_ARGS__), metamacro_take5(metamacro_tail(__VA_ARGS__))
#define metamacro_take7(...) metamacro_head(__VA_ARGS__), metamacro_take6(metamacro_tail(__VA_ARGS__))
#define metamacro_take8(...) metamacro_head(__VA_ARGS__), metamacro_take7(metamacro_tail(__VA_ARGS__))
#define metamacro_take9(...) metamacro_head(__VA_ARGS__), metamacro_take8(metamacro_tail(__VA_ARGS__))
#define metamacro_take10(...) metamacro_head(__VA_ARGS__), metamacro_take9(metamacro_tail(__VA_ARGS__))
#define metamacro_take11(...) metamacro_head(__VA_ARGS__), metamacro_take10(metamacro_tail(__VA_ARGS__))
#define metamacro_take12(...) metamacro_head(__VA_ARGS__), metamacro_take11(metamacro_tail(__VA_ARGS__))
#define metamacro_take13(...) metamacro_head(__VA_ARGS__), metamacro_take12(metamacro_tail(__VA_ARGS__))
#define metamacro_take14(...) metamacro_head(__VA_ARGS__), metamacro_take13(metamacro_tail(__VA_ARGS__))
#define metamacro_take15(...) metamacro_head(__VA_ARGS__), metamacro_take14(metamacro_tail(__VA_ARGS__))
#define metamacro_take16(...) metamacro_head(__VA_ARGS__), metamacro_take15(metamacro_tail(__VA_ARGS__))
#define metamacro_take17(...) metamacro_head(__VA_ARGS__), metamacro_take16(metamacro_tail(__VA_ARGS__))
#define metamacro_take18(...) metamacro_head(__VA_ARGS__), metamacro_take17(metamacro_tail(__VA_ARGS__))
#define metamacro_take19(...) metamacro_head(__VA_ARGS__), metamacro_take18(metamacro_tail(__VA_ARGS__))
#define metamacro_take20(...) metamacro_head(__VA_ARGS__), metamacro_take19(metamacro_tail(__VA_ARGS__))
// metamacro_drop expansions
#define metamacro_drop0(...) __VA_ARGS__
#define metamacro_drop1(...) metamacro_tail(__VA_ARGS__)
#define metamacro_drop2(...) metamacro_drop1(metamacro_tail(__VA_ARGS__))
#define metamacro_drop3(...) metamacro_drop2(metamacro_tail(__VA_ARGS__))
#define metamacro_drop4(...) metamacro_drop3(metamacro_tail(__VA_ARGS__))
#define metamacro_drop5(...) metamacro_drop4(metamacro_tail(__VA_ARGS__))
#define metamacro_drop6(...) metamacro_drop5(metamacro_tail(__VA_ARGS__))
#define metamacro_drop7(...) metamacro_drop6(metamacro_tail(__VA_ARGS__))
#define metamacro_drop8(...) metamacro_drop7(metamacro_tail(__VA_ARGS__))
#define metamacro_drop9(...) metamacro_drop8(metamacro_tail(__VA_ARGS__))
#define metamacro_drop10(...) metamacro_drop9(metamacro_tail(__VA_ARGS__))
#define metamacro_drop11(...) metamacro_drop10(metamacro_tail(__VA_ARGS__))
#define metamacro_drop12(...) metamacro_drop11(metamacro_tail(__VA_ARGS__))
#define metamacro_drop13(...) metamacro_drop12(metamacro_tail(__VA_ARGS__))
#define metamacro_drop14(...) metamacro_drop13(metamacro_tail(__VA_ARGS__))
#define metamacro_drop15(...) metamacro_drop14(metamacro_tail(__VA_ARGS__))
#define metamacro_drop16(...) metamacro_drop15(metamacro_tail(__VA_ARGS__))
#define metamacro_drop17(...) metamacro_drop16(metamacro_tail(__VA_ARGS__))
#define metamacro_drop18(...) metamacro_drop17(metamacro_tail(__VA_ARGS__))
#define metamacro_drop19(...) metamacro_drop18(metamacro_tail(__VA_ARGS__))
#define metamacro_drop20(...) metamacro_drop19(metamacro_tail(__VA_ARGS__))
#endif
@@ -0,0 +1,6 @@
framework module DypaySDK {
umbrella header "DypaySDK-umbrella.h"
export *
module * { export * }
}
@@ -0,0 +1,4 @@
#import <Foundation/Foundation.h>
#import "DypayDIRSFMDatabase.h"
#import "DypayDIRSFMResultSet.h"
#import "DypayDIRSFMDatabaseQueue.h"
@@ -0,0 +1,149 @@
//
// DypayAPI.h
// DypaySDK
//
// Created by xutianxi on 2021/12/10.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, DypayErrorCode) {
DypayErrorCodeSuccess = 0, // 成功
DypayErrorCodeCancel = 1, // 用户取消
DypayErrorCodeFail = 2, // 失败
DypayErrorCodeProcessing = 3, // 支付结果处理中
DypayErrorCodeVersionTooLow = 100, // 抖音版本过低,需要用户升级
};
typedef NS_ENUM(NSInteger, DypayLogLevel) {
DypayLogLevelOff = 0,
DypayLogLevelError = 1,
DypayLogLevelWarn = 2,
DypayLogLevelInfo = 3,
DypayLogLevelDebug = 4,
};
#define DYPAYSDK_TAG @"DypaySDK"
#define DYPAY_RECALL_API_MAX_TIME 3000 //毫秒级
#define SHARED_SELF DypayAPI.sharedDypayAPI
@interface DypayAPI : NSObject
// 日志记录Block,可查看运行过程中的信息
@property (nonatomic, copy) void(^logBlock)(DypayLogLevel level, NSTimeInterval timestamp, NSString *tag, NSString *message);
/**
* 支付单例
*
* @return 返回单例对象
*/
+ (DypayAPI *)sharedDypayAPI;
/*
* @param appId 从抖音商户平台申请的appId
* @param scheme 从抖音回调当前 App 时使用的 scheme
*/
+ (void)registerWithAppID:(NSString *)appId
callbackScheme:(NSString *)scheme;
/*
* @param appId 从抖音商户平台申请的appId,优先使用universalLink,降级使用scheme
* @param universalLink 从抖音回调当前 App 时使用的universalLink
* @param scheme 从抖音回调当前 App 时使用的 scheme
*/
+ (void)registerWithAppID:(NSString *)appId
universalLink:(NSString *)universalLink
callbackScheme:(NSString *)scheme;
/*
* 判断是否能打开 Dypay
*/
+ (bool)canOpenDypay;
/*
* @brief 打开 Dypay, 打开成功后马上回调 completionBlock,
* @param infoDict 拉起抖音支付必须的订单参数
* @param currentTopViewController 拉起抖音支付时顶部的vc
* @param callback 调用结果的回调
*/
+ (void)openDypayWithInfo:(NSDictionary *)infoDict
fromViewController:(UIViewController *)currentTopViewController
callback:(void(^)(BOOL isOpenedSuccessed, NSString *errMsg))completionBlock DEPRECATED_MSG_ATTRIBUTE("call openDypayWithInfo:fromViewController:resultCallback instead");
/*
* @brief 打开 Dypay,唤端之前:支付结果会通过该API的resultCallback参数回调,唤端之后:支付结果通过processDypayResultWithURL的callback回调
* @param infoDict 拉起抖音支付必须的订单参数
* @param currentTopViewController 拉起抖音支付时顶部的vc
* @param resultCallback 支付结果的回调,resultCode枚举参照processDypayResultWithURL注释
*/
+ (void)openDypayWithInfo:(NSDictionary *)infoDict
fromViewController:(UIViewController *)currentTopViewController
resultCallback:(void(^)(NSDictionary *resultDict))resultCompletionBlock;
/*
* 处理通过URL支付回调结果
* resultDict 包含支付结果错误码信息,如果为nil也表示处理失败。
字典中,key: "resultStatus"对应老的错误码定义,将逐步废弃;请使用新key: "resultCode"对应的错误码定义。
老key: resultStatus,对应的错误码定义:
-1 未知
0 订单支付成功
10 用户中途取消
20 正在处理中
30 版本过低
40 失败
50 超时
新key: resultCode,对应的错误码定义
DypayErrorCodeSuccess(0) 成功
DypayErrorCodeCancel(1) 用户取消
DypayErrorCodeFail(2) 失败
DypayErrorCodeProcessing(3) 支付结果处理中
DypayErrorCodeVersionTooLow(100) 抖音版本过低,需要用户升级
*/
+ (BOOL)processDypayResultWithURL:(NSURL *)url
callback:(void(^)(NSDictionary * _Nullable resultDict))completionBlock;
/*
* 处理通过Universal Link支付回调结果
* resultDict 包含支付结果错误码信息,如果为nil也表示处理失败。
字典中,key: "resultStatus"对应老的错误码定义,将逐步废弃;请使用新key: "resultCode"对应的错误码定义。
老key: resultStatus,对应的错误码定义:
-1 未知
0 订单支付成功
10 用户中途取消
20 正在处理中
30 版本过低
40 失败
50 超时
新key: resultCode,对应的错误码定义
DypayErrorCodeSuccess(0) 成功
DypayErrorCodeCancel(1) 用户取消
DypayErrorCodeFail(2) 失败
DypayErrorCodeProcessing(3) 支付结果处理中
DypayErrorCodeVersionTooLow(100) 抖音版本过低,需要用户升级
*/
+ (BOOL)processDypayResultWithUserActivity:(NSUserActivity *)userActivity
callback:(void(^)(NSDictionary *resultDict))completionBlock;
/*! @brief 获取当前 DypaySDK API 的版本号
*/
+ (NSString *)getAPIVersion;
/*
* 埋点
*/
+ (void)event:(NSString *_Nonnull)eventName params:(NSDictionary *_Nullable)params;
@end
// 内部接口,字节外部App不应使用
@interface DypayAPI (Internal)
// 业务埋点上报Block,字节内部App使用时设置
@property (nonatomic, copy) void(^trackEventBlock)(NSString *event, NSDictionary *params);
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,32 @@
//
// DypayDIRSApplication.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/13.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSInteger, DypayIRISApplicationState) {
DypayIRISApplicationStateUnknown = 0,
DypayIRISApplicationStateActive,
DypayIRISApplicationStateInactive,
DypayIRISApplicationStateBackground
};
@interface DypayDIRSApplication : NSObject
@property (readonly, nonnull) NSString *launchID;
@property (readonly, assign) NSTimeInterval launchTime;
@property (readonly) DypayIRISApplicationState applicationState;
+ (instancetype)sharedApplication;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,20 @@
//
// DypayDIRSBasicFeatureOptions.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/11/9.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSBasicFeatureOptions : DypayDIRSBasicModule
- (void)addFeatureOptions:(NSDictionary *)opts;
- (void)removeFeatureOptionsKeys:(NSArray *)keys;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,35 @@
//
// DypayDIRSBasicModule.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/11.
//
#import <Foundation/Foundation.h>
#import "DypayIRISInterfaceDefines.h"
#import "DypayIRISMacro.h"
#import "DypayDIRSContext.h"
#import "DypayDIRSModuleHive.h"
#import "IRSLOG.h"
#import "DypayDataIRIS.h"
NS_ASSUME_NONNULL_BEGIN
@class DypayDIRSContext;
@interface DypayDIRSBasicModule : NSObject<DypayIRISModule>
@property (nonatomic, weak) DypayDIRSContext* context;
@property (nullable, nonatomic, copy) NSString* category;
@property BOOL isEnabled;
@property DypayIRISState state;
- (void)onLaunch;
- (void)run;
- (void)stop;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,16 @@
//
// DypayDIRSCompressionGzipPlugin.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/8/9.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSCompressionGzipPlugin : DypayDIRSBasicModule<DypayIRISModuleGlobal, DypayIRISDataCoder>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,24 @@
//
// DypayDIRSConcurrentCollection.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/11.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSConcurrentCollection<T> : NSObject
+ (instancetype)collectionWithRaw:(T)collection;
- (void)operate:(void (^)(T raw))operation;
- (nullable id)access:(nullable id (^)(T raw))operation;
- (T)rawValue;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,193 @@
//
// DypayDIRSConfig.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/11.
//
#import <Foundation/Foundation.h>
#import "DypayIRISDefines.h"
NS_ASSUME_NONNULL_BEGIN
@class DypayDIRSComplianceConfiguration,DypayDIRSEventConfiguration,DypayDIRSObserver,DypayDIRSEventUploadFilterOptions;
@interface DypayDIRSConfig : NSObject
+ (instancetype _Nullable)configWithIdentifier:(NSString *_Nonnull)appId
launchOptions:(nullable NSDictionary *)launchOptions;
@property (nullable, nonatomic, copy) NSString *appId;
@property (nullable, nonatomic, copy) NSString *appName;
@property (nullable, nonatomic, copy) NSString *appVersion;
@property (nullable, nonatomic, copy) NSString *buildVersion;
//If you need to synchronize data between HostApp and ExtensionApp, you need to set the same groupId
@property (nullable, nonatomic, copy) NSString *appGroupId;
@property (nullable, nonatomic, copy) NSString *channel;
//be able to distinguish between different instances using the same appid
@property (nullable, nonatomic, copy) NSString *subId;
@property (nonatomic, strong ) NSDictionary *launchOptions;
@property (nonatomic, assign) BOOL encryptionEnabled;
@property (nullable, nonatomic, strong) id<DypayIRISEndpoint> endpoint;
///The default log level is Error
@property (nonatomic, assign) DypayIRISLOG_LEVEL logLevel;
@property (nullable, nonatomic, copy) void (^configureUserLoggerBlock)(id<DypayIRISLog> _Nullable log);
@property (nullable, readonly) DypayDIRSComplianceConfiguration* compliance;
@property (nullable, readonly) DypayDIRSEventConfiguration* event;
@property (nullable, readonly) DypayDIRSObserver *observer;
@property (nullable, nonatomic, copy) NSDictionary<NSString*, NSString *> *_Nullable (^configureHTTPHeaderFieldsBlock)(NSUInteger service);
@property (nullable, nonatomic, copy) NSDictionary<NSString*, id> *_Nullable (^configureCommonParametersBlock)(NSUInteger service);
@property (nullable, nonatomic, copy) NSDictionary<NSString*, id> *_Nullable (^configureCustomHeaderBlock)(NSUInteger service);
@property (nullable, nonatomic, copy) void (^onError)(BOOL fatal, NSError * _Nonnull error, id _Nullable userInfo);
@end
@interface DypayDIRSComplianceConfiguration : NSObject
/**
* @brief fields to avoid access
*
* @discussion Fields set in @c blockedFiels will not be accessed and uploaded.
* For example, if you you do not want to collect @c vendor_id, set the following code block, then @c UIDevice.identifierForVendor will not be accessed, and the field @c vendor_id will not appear in any HTTPBODY
*
* @code
* config.compliance.blockedFields = @[@"vendor_id"];
* @endcode
*
*/
@property (nullable, nonatomic, copy) NSArray *blockedFields;
@end
@interface DypayDIRSEventConfiguration : NSObject
/*
* Intercept or change events before they are stored
*/
@property (nullable, nonatomic, copy) void (^configureEventInterceptorBlock)(id<DypayIRISEvent> _Nullable event, BOOL * _Nonnull stop);
/*
* Filter events before packaging
*
*/
@property (nullable, nonatomic, copy) _Nullable id (^configurePreBatchFilterBlock)(id _Nullable context);
@property (nullable, nonatomic, copy) _Nullable id (^configureEventPacketBlock)(id<DypayIRISEvent> _Nullable event, BOOL * _Nonnull stop);
/*
*
* Event expiration time [Unit:seconds]
* Data will be cleaned based on expiration time every time on startup
* Setting it to 0 will not clean up the data.
*
* Default is 0
*
*/
@property (nonatomic, assign) NSUInteger eventExpirationTime;
/*
* - DypayIRISEventPacketStrategyDefault
* Packaging based on the upper limit of the number of events, The number of upper limit can be set through maxPacketEventCount, the default is 200
* - DypayIRISEventPacketStrategyByteLimitation
* Packing based on the upper limit of data length, The length can be set through maxPacketBytes, the default is 1024*1024
*
* Default is DypayIRISEventPacketStrategyDefault
*
*/
@property (nonatomic, assign) DypayIRISEventPacketStrategy packetStrategy;
/*
*
* Default is 200
* takes effect when setting config.event.packetStrategy = DypayIRISEventPacketStrategyDefault
*
*/
@property (nonatomic, assign) NSUInteger maxPacketEventCount;
/*
*
* Default is 1m
* takes effect when setting config.event.packetStrategy = DypayIRISEventPacketStrategyByteLimitation
*
*/
@property (nonatomic, assign) NSUInteger maxPacketBytes;
/*
* Default is 500m, some(25%) earliest events will be deleted when the maximum limit is exceeded on startup
When an error occurs in the data file and the size of the database file cannot be successfully reduced
in order to avoid affecting the stability of the application,
the database file will be removed as a whole, which will cause events loss
*/
@property (nonatomic, assign) NSUInteger maxFileBytes;
/*
* Maximum length after serialization
* default 20*1024;
*
* @NOT take effect yet
*/
@property (nonatomic, assign) NSUInteger maxPropertyBytes;
@end
@interface DypayDIRSEventUploadFilterOptions : NSObject
@property (nullable, nonatomic, strong) NSArray<NSString *> *regionKeys;
@property (nullable, nonatomic, strong) NSArray<NSString *> *includeTypes;
@property (nullable, nonatomic, strong) NSArray<NSString *> *excludeTypes;
@end
@interface DypayDIRSObserver : NSObject
@property (nullable, nonatomic, copy) void (^onSessionLaunch)(NSString *sessionId, id _Nullable info);
@property (nullable, nonatomic, copy) void (^onSessionTerminate)(NSString *sessionId, id _Nullable info);
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,67 @@
//
// DypayDIRSContext.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/11.
//
#import <Foundation/Foundation.h>
#import "DypayIRISInterfaceDefines.h"
NS_ASSUME_NONNULL_BEGIN
@class DypayDIRSConfig,DypayDIRSLogger,DypayDIRSModuleHive;
@interface DypayDIRSContext : NSObject
@property (nonatomic, readonly) DypayDIRSModuleHive* modular;
@property (readonly, nullable) DypayDIRSConfig *config;
@property (readonly, nonnull) NSString *name;
+ (instancetype)main;
+ (void)configure:(DypayDIRSConfig *)config;
- (instancetype)initWithConfig:(DypayDIRSConfig *)config;
- (BOOL)resume;
- (void)suspend;
- (nonnull NSString *)contextPath;
- (void)async:(dispatch_block_t)block;
- (nonnull NSDictionary *)contextInfo;
- (void)dispose;
- (BOOL)isMainContext;
@end
@interface DypayDIRSContext (Instance)
+ (NSArray<DypayDIRSContext *> *)ctx_all;
+ (nullable DypayDIRSContext *)ctx_get:(NSString *)name;
+ (void)ctx_add:(DypayDIRSContext *)context;
+ (void)ctx_remove:(DypayDIRSContext *)context;
@end
@interface DypayDIRSContext (Modules)
@property (nullable, nonatomic, readonly) DypayDIRSLogger *logger;
- (nullable NSDictionary *)modules;
+ (NSDictionary *)defaultModules;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,25 @@
//
// DypayDIRSEndpointConfiguration.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/24.
//
#import <Foundation/Foundation.h>
#import "DypayIRISDefines.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEndpointConfiguration : NSObject<DypayIRISEndpoint>
@property (nullable, nonatomic, copy) id _Nullable (^domainBlock)(NSUInteger service, id context);
@property (nullable, nonatomic, copy) id _Nullable (^endpointBlock)(NSUInteger service, id context);
+ (DypayDIRSEndpointConfiguration *)configurationUsingBlock:(nonnull id (^)(NSUInteger service, id context))block;
+ (DypayDIRSEndpointConfiguration *)configurationUsingDomainBlock:(nonnull id (^)(NSUInteger service, id context))block;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,29 @@
//
// DypayDIRSEnviroment.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/25.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEnviroment : DypayDIRSBasicModule<DypayIRISParameterHandler,DypayIRISModuleGlobal>
+ (NSInteger)sdkVersion;
+ (NSString *)sdkVersionString;
+ (NSString *)osName;
+ (NSString *)osVersion;
+ (NSString *)platform;
+ (NSString *)appVersion;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,34 @@
//
// DypayDIRSErrorBuilder.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/13.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSErrorBuilder : NSObject
+ (instancetype)builder;
- (instancetype)withDomain:(NSErrorDomain)code;
- (instancetype)withCode:(NSUInteger)code;
- (instancetype)withDescription:(NSString *)description;
- (instancetype)withDescriptionFormat:(NSString *)format, ...;
- (instancetype)withFailureReason:(NSString *)reason;
- (instancetype)withUnderlyingError:(NSError *)error;
- (NSError *)build;
- (BOOL)buildError:(NSError **)error;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,106 @@
//
// DypayDIRSEvent.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/13.
//
#import <Foundation/Foundation.h>
#import "DypayIRISDefinesPrivate.h"
typedef NSString * DypayIRISEventType;
FOUNDATION_EXTERN DypayIRISEventType const _Nonnull DypayDIRSEventTypeV3; //event_v3
NS_ASSUME_NONNULL_BEGIN
@class DypayDIRSEventOptions;
@interface DypayDIRSEvent : NSObject<DypayIRISEvent, NSCoding>
@property (nullable, nonatomic, copy) NSString * key;
@property (nullable, nonatomic, copy) NSString * type;
@property (nonatomic) NSTimeInterval time;
@property (nonatomic) NSTimeInterval storedTime;
@property (nonatomic) NSTimeInterval batchedTime;
@property (nullable, nonatomic, strong) NSDictionary * properties;
@property (nullable, nonatomic, strong) NSDictionary * globalProperties;
@property (nullable, nonatomic, strong) NSDictionary * commonParameters;
@property (nullable, nonatomic, copy) NSString * logID;
@property (nullable, nonatomic, copy) NSNumber* dbIndex;
@property (nonatomic, assign) int64_t index;
@property (nonatomic, copy) NSString* section;
@property (nullable, nonatomic) id schemaObject;
@property (nonatomic, assign) NSUInteger schemaDataLength;
@property (nonatomic, strong) DypayDIRSEventOptions * options;
@property (nonatomic, assign) BOOL stained;
//return event_id if event stained
- (int64_t)staining;
- (NSString *)sessionId;
- (void)addCommonParameters:(NSDictionary *)parameters;
+ (nullable instancetype)eventWithType:(DypayIRISEventType _Nonnull)type
properties:(NSDictionary * _Nullable)properties;
+ (nullable instancetype)v3UsingKey:(NSString * _Nonnull)key
properties:(NSDictionary * _Nullable)properties;
@end
@interface DypayDIRSEventOptions : NSObject
@property (nonatomic, assign) NSInteger category;
@property (nonatomic, assign) DypayIRISPriority priority;
@property (nullable ,nonatomic, copy) NSString * regionKey;
@property (nonatomic, assign) NSInteger privacyLevel;
@property (nonatomic, assign) BOOL filtered;
@end
@interface DypayDIRSEventBatchOptions : NSObject
@property (nonatomic, assign) NSInteger priority;
@property (nullable, nonatomic) NSArray * eventIDs;
@property (nonatomic, assign) NSUInteger count;
@property (nonatomic, strong) NSArray * allowRegionList;
@property (nonatomic, assign) NSInteger minDBIndex;
@property (nonatomic, assign) NSInteger maxDBIndex;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,29 @@
//
// DypayDIRSEventUploadDispatcher.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/18.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventBatchDispatcher : DypayDIRSBasicModule
@property (nonatomic, readonly) id<DypayIRISServiceSchema> schema;
@property (readonly) id<DypayIRISEventUploadExecutor> defaultUploader;
@property (readonly) id<DypayIRISEventUploadExecutor> realtimeUploader;
- (nullable id<DypayIRISEventUploadExecutor>)createExecutor;
- (nullable NSArray<DypayIRISEventUploadExecutor> *)allExecutors;
- (nonnull dispatch_queue_t)intervalBatchQueue;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,50 @@
//
// DypayDIRSEventUploadExecutor.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/18.
//
#import "DypayDIRSBasicModule.h"
#import "DypayIRISInterfaceDefines.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventBatchExecutor : DypayDIRSBasicModule<DypayIRISEventUploadExecutor>
@property (nonatomic, assign) NSTimeInterval interval;
@property (nullable, nonatomic, weak) id<DypayIRISServiceSchema> serializer;
@property (nullable, nonatomic) NSArray<id<DypayIRISDataCoder>> *compressors;
@property (nullable, nonatomic, weak) id<DypayIRISDataCoder> encryptor;
@property (nullable, nonatomic, weak) id<DypayIRISDataCoder> decryptor;
@property (nullable, nonatomic, weak) id<DypayIRISEventStore> eventStore;
@property (nullable, nonatomic) id<DypayIRISThrottlter> throttlter;
@property (nonatomic, assign) DypayIRISPriority priority;
@property (nonatomic, assign) DypayIRISState execState;
@property (nullable, nonatomic, strong) NSDictionary *options;
/*
* @opts
* DypayIRISBatchOptionsEnforceKey - enforce batch YES|NO
*
*/
//- (void)executeUpload:(DypayIRISBatchTrigger)trigger
// options:(nullable NSDictionary *)opts
// completion:(void (^ __nullable)(BOOL success, NSError* _Nullable error))completion;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,16 @@
//
// DypayDIRSEventBlockPlugin.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/8/25.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventBlockPlugin : DypayDIRSBasicModule
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,18 @@
//
// DypayDIRSEventEntry.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/13.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventEntry : DypayDIRSBasicModule<DypayIRISModule, DypayIRISTracker>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,17 @@
//
// DypayDIRSEventListener.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/8/14.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventListener : DypayDIRSBasicModule
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,22 @@
//
// DypayDIRSEventPacker.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/18.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventPacker : NSObject<DypayIRISEventPacker>
@property (nonatomic, assign) NSUInteger maxPackLength;
@property (nonatomic, assign) NSUInteger maxEventCount;
@property (nonatomic, assign) NSInteger strategy;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,23 @@
//
// DypayDIRSEventRequestSchema.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/18.
//
#import "DypayDIRSBasicModule.h"
#import "DypayDIRSEventPacker.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventRequestSchema : DypayDIRSBasicModule<DypayIRISServiceSchema,DypayIRISModuleGlobal>
@end
@interface DypayDIRSEventRealtimeRequestSchema : DypayDIRSEventRequestSchema<DypayIRISServiceSchema, DypayIRISModuleGlobal>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,16 @@
//
// DypayDIRSEventSerializer.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/14.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventSerializer : DypayDIRSBasicModule<DypayIRISEventSerializer>
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,20 @@
//
// DypayDIRSEventSession.h
//
//
// Created by ByteDance on 2023/8/4.
//
#import "DypayDIRSBasicModule.h"
#import "DypayDataIRIS.h"
#import "DypayDIRSTracker+Session.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventSession : DypayDIRSBasicModule
@property (nonatomic, assign) DypayIRISLaunchType launchType;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,24 @@
//
// DypayDIRSEventStore.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/13.
//
#import "DypayDIRSBasicModule.h"
#import "DypayDIRSEvent.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSEventStore : DypayDIRSBasicModule<DypayIRISEventStore>
@property (nonatomic, weak) id<DypayIRISEventSerializer> serializer;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,31 @@
//
// DypayDIRSExtension.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/11.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface NSDictionary (DypayDataIRIS)
- (nullable NSDictionary *)datairis_dictionaryForKey:(NSString *)key;
- (nullable NSString *)datairis_stringForKey:(NSString *)key;
- (nullable NSArray *)datairis_arrayForKey:(NSString *)key;
- (double)datairis_doubleForKey:(NSString *)key;
- (NSInteger)datairis_integerForKey:(NSString *)key;
- (BOOL)datairis_boolForKey:(NSString *)key;
- (long long)datairis_longlongValueForKey:(NSString *)key;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,182 @@
//
// DypayDIRSFMDatabaseQueue.h
// fmdb
//
// Created by August Mueller on 6/22/11.
// Copyright 2011 Flying Meat Inc. All rights reserved.
//
#import <Foundation/Foundation.h>
@class DypayDIRSFMDatabase;
/** To perform queries and updates on multiple threads, you'll want to use `DypayDIRSFMDatabaseQueue`.
Using a single instance of `<DypayDIRSFMDatabase>` from multiple threads at once is a bad idea. It has always been OK to make a `<DypayDIRSFMDatabase>` object *per thread*. Just don't share a single instance across threads, and definitely not across multiple threads at the same time.
Instead, use `DypayDIRSFMDatabaseQueue`. Here's how to use it:
First, make your queue.
DypayDIRSFMDatabaseQueue *queue = [DypayDIRSFMDatabaseQueue databaseQueueWithPath:aPath];
Then use it like so:
[queue inDatabase:^(DypayDIRSFMDatabase *db) {
[db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:1]];
[db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:2]];
[db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:3]];
DypayDIRSResultSet *rs = [db executeQuery:@"select * from foo"];
while ([rs next]) {
//…
}
}];
An easy way to wrap things up in a transaction can be done like this:
[queue inTransaction:^(DypayDIRSFMDatabase *db, BOOL *rollback) {
[db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:1]];
[db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:2]];
[db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:3]];
if (whoopsSomethingWrongHappened) {
*rollback = YES;
return;
}
// etc…
[db executeUpdate:@"INSERT INTO myTable VALUES (?)", [NSNumber numberWithInt:4]];
}];
`DypayDIRSFMDatabaseQueue` will run the blocks on a serialized queue (hence the name of the class). So if you call `DypayDIRSFMDatabaseQueue`'s methods from multiple threads at the same time, they will be executed in the order they are received. This way queries and updates won't step on each other's toes, and every one is happy.
### See also
- `<DypayDIRSFMDatabase>`
@warning Do not instantiate a single `<DypayDIRSFMDatabase>` object and use it across multiple threads. Use `DypayDIRSFMDatabaseQueue` instead.
@warning The calls to `DypayDIRSFMDatabaseQueue`'s methods are blocking. So even though you are passing along blocks, they will **not** be run on another thread.
*/
@interface DypayDIRSFMDatabaseQueue : NSObject {
NSString *_path;
dispatch_queue_t _queue;
DypayDIRSFMDatabase *_db;
int _openFlags;
}
/** Path of database */
@property (atomic, retain) NSString *path;
/** Open flags */
@property (atomic, readonly) int openFlags;
///----------------------------------------------------
/// @name Initialization, opening, and closing of queue
///----------------------------------------------------
/** Create queue using path.
@param aPath The file path of the database.
@return The `DypayDIRSFMDatabaseQueue` object. `nil` on error.
*/
+ (instancetype)databaseQueueWithPath:(NSString*)aPath;
/** Create queue using path and specified flags.
@param aPath The file path of the database.
@param openFlags Flags passed to the openWithFlags method of the database
@return The `DypayDIRSFMDatabaseQueue` object. `nil` on error.
*/
+ (instancetype)databaseQueueWithPath:(NSString*)aPath flags:(int)openFlags;
/** Create queue using path.
@param aPath The file path of the database.
@return The `DypayDIRSFMDatabaseQueue` object. `nil` on error.
*/
- (instancetype)initWithPath:(NSString*)aPath;
/** Create queue using path and specified flags.
@param aPath The file path of the database.
@param openFlags Flags passed to the openWithFlags method of the database
@return The `DypayDIRSFMDatabaseQueue` object. `nil` on error.
*/
- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags;
/** Create queue using path and specified flags.
@param aPath The file path of the database.
@param openFlags Flags passed to the openWithFlags method of the database
@param vfsName The name of a custom virtual file system
@return The `DypayDIRSFMDatabaseQueue` object. `nil` on error.
*/
- (instancetype)initWithPath:(NSString*)aPath flags:(int)openFlags vfs:(NSString *)vfsName;
/** Returns the Class of 'DypayDIRSFMDatabase' subclass, that will be used to instantiate database object.
Subclasses can override this method to return specified Class of 'DypayDIRSFMDatabase' subclass.
@return The Class of 'DypayDIRSFMDatabase' subclass, that will be used to instantiate database object.
*/
+ (Class)databaseClass;
/** Close database used by queue. */
- (void)close;
///-----------------------------------------------
/// @name Dispatching database operations to queue
///-----------------------------------------------
/** Synchronously perform database operations on queue.
@param block The code to be run on the queue of `DypayDIRSFMDatabaseQueue`
*/
- (void)inDatabase:(void (^)(DypayDIRSFMDatabase *db))block;
/** Synchronously perform database operations on queue, using transactions.
@param block The code to be run on the queue of `DypayDIRSFMDatabaseQueue`
*/
- (void)inTransaction:(void (^)(DypayDIRSFMDatabase *db, BOOL *rollback))block;
/** Synchronously perform database operations on queue, using deferred transactions.
@param block The code to be run on the queue of `DypayDIRSFMDatabaseQueue`
*/
- (void)inDeferredTransaction:(void (^)(DypayDIRSFMDatabase *db, BOOL *rollback))block;
///-----------------------------------------------
/// @name Dispatching database operations to queue
///-----------------------------------------------
/** Synchronously perform database operations using save point.
@param block The code to be run on the queue of `DypayDIRSFMDatabaseQueue`
*/
// NOTE: you can not nest these, since calling it will pull another database out of the pool and you'll get a deadlock.
// If you need to nest, use DypayDIRSFMDatabase's startSavePointWithName:error: instead.
- (NSError*)inSavePoint:(void (^)(DypayDIRSFMDatabase *db, BOOL *rollback))block;
@end
@@ -0,0 +1,468 @@
#import <Foundation/Foundation.h>
#ifndef __has_feature // Optional.
#define __has_feature(x) 0 // Compatibility with non-clang compilers.
#endif
#ifndef NS_RETURNS_NOT_RETAINED
#if __has_feature(attribute_ns_returns_not_retained)
#define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))
#else
#define NS_RETURNS_NOT_RETAINED
#endif
#endif
@class DypayDIRSFMDatabase;
@class DypayDIRSStatement;
/** Represents the results of executing a query on an `<DypayDIRSFMDatabase>`.
### See also
- `<DypayDIRSFMDatabase>`
*/
@interface DypayDIRSResultSet : NSObject {
DypayDIRSFMDatabase *_parentDB;
DypayDIRSStatement *_statement;
NSString *_query;
NSMutableDictionary *_columnNameToIndexMap;
}
///-----------------
/// @name Properties
///-----------------
/** Executed query */
@property (atomic, retain) NSString *query;
/** `NSMutableDictionary` mapping column names to numeric index */
@property (readonly) NSMutableDictionary *columnNameToIndexMap;
/** `DypayDIRSStatement` used by result set. */
@property (atomic, retain) DypayDIRSStatement *statement;
///------------------------------------
/// @name Creating and closing database
///------------------------------------
/** Create result set from `<DypayDIRSStatement>`
@param statement A `<DypayDIRSStatement>` to be performed
@param aDB A `<DypayDIRSFMDatabase>` to be used
@return A `DypayDIRSResultSet` on success; `nil` on failure
*/
+ (instancetype)resultSetWithStatement:(DypayDIRSStatement *)statement usingParentDatabase:(DypayDIRSFMDatabase*)aDB;
/** Close result set */
- (void)close;
- (void)setParentDB:(DypayDIRSFMDatabase *)newDb;
///---------------------------------------
/// @name Iterating through the result set
///---------------------------------------
/** Retrieve next row for result set.
You must always invoke `next` or `nextWithError` before attempting to access the values returned in a query, even if you're only expecting one.
@return `YES` if row successfully retrieved; `NO` if end of result set reached
@see hasAnotherRow
*/
- (BOOL)next;
/** Retrieve next row for result set.
You must always invoke `next` or `nextWithError` before attempting to access the values returned in a query, even if you're only expecting one.
@param outErr A 'NSError' object to receive any error object (if any).
@return 'YES' if row successfully retrieved; 'NO' if end of result set reached
@see hasAnotherRow
*/
- (BOOL)nextWithError:(NSError **)outErr;
/** Did the last call to `<next>` succeed in retrieving another row?
@return `YES` if the last call to `<next>` succeeded in retrieving another record; `NO` if not.
@see next
@warning The `hasAnotherRow` method must follow a call to `<next>`. If the previous database interaction was something other than a call to `next`, then this method may return `NO`, whether there is another row of data or not.
*/
- (BOOL)hasAnotherRow;
///---------------------------------------------
/// @name Retrieving information from result set
///---------------------------------------------
/** How many columns in result set
@return Integer value of the number of columns.
*/
- (int)columnCount;
/** Column index for column name
@param columnName `NSString` value of the name of the column.
@return Zero-based index for column.
*/
- (int)columnIndexForName:(NSString*)columnName;
/** Column name for column index
@param columnIdx Zero-based index for column.
@return columnName `NSString` value of the name of the column.
*/
- (NSString*)columnNameForIndex:(int)columnIdx;
/** Result set integer value for column.
@param columnName `NSString` value of the name of the column.
@return `int` value of the result set's column.
*/
- (int)intForColumn:(NSString*)columnName;
/** Result set integer value for column.
@param columnIdx Zero-based index for column.
@return `int` value of the result set's column.
*/
- (int)intForColumnIndex:(int)columnIdx;
/** Result set `long` value for column.
@param columnName `NSString` value of the name of the column.
@return `long` value of the result set's column.
*/
- (long)longForColumn:(NSString*)columnName;
/** Result set long value for column.
@param columnIdx Zero-based index for column.
@return `long` value of the result set's column.
*/
- (long)longForColumnIndex:(int)columnIdx;
/** Result set `long long int` value for column.
@param columnName `NSString` value of the name of the column.
@return `long long int` value of the result set's column.
*/
- (long long int)longLongIntForColumn:(NSString*)columnName;
/** Result set `long long int` value for column.
@param columnIdx Zero-based index for column.
@return `long long int` value of the result set's column.
*/
- (long long int)longLongIntForColumnIndex:(int)columnIdx;
/** Result set `unsigned long long int` value for column.
@param columnName `NSString` value of the name of the column.
@return `unsigned long long int` value of the result set's column.
*/
- (unsigned long long int)unsignedLongLongIntForColumn:(NSString*)columnName;
/** Result set `unsigned long long int` value for column.
@param columnIdx Zero-based index for column.
@return `unsigned long long int` value of the result set's column.
*/
- (unsigned long long int)unsignedLongLongIntForColumnIndex:(int)columnIdx;
/** Result set `BOOL` value for column.
@param columnName `NSString` value of the name of the column.
@return `BOOL` value of the result set's column.
*/
- (BOOL)boolForColumn:(NSString*)columnName;
/** Result set `BOOL` value for column.
@param columnIdx Zero-based index for column.
@return `BOOL` value of the result set's column.
*/
- (BOOL)boolForColumnIndex:(int)columnIdx;
/** Result set `double` value for column.
@param columnName `NSString` value of the name of the column.
@return `double` value of the result set's column.
*/
- (double)doubleForColumn:(NSString*)columnName;
/** Result set `double` value for column.
@param columnIdx Zero-based index for column.
@return `double` value of the result set's column.
*/
- (double)doubleForColumnIndex:(int)columnIdx;
/** Result set `NSString` value for column.
@param columnName `NSString` value of the name of the column.
@return `NSString` value of the result set's column.
*/
- (NSString*)stringForColumn:(NSString*)columnName;
/** Result set `NSString` value for column.
@param columnIdx Zero-based index for column.
@return `NSString` value of the result set's column.
*/
- (NSString*)stringForColumnIndex:(int)columnIdx;
/** Result set `NSDate` value for column.
@param columnName `NSString` value of the name of the column.
@return `NSDate` value of the result set's column.
*/
- (NSDate*)dateForColumn:(NSString*)columnName;
/** Result set `NSDate` value for column.
@param columnIdx Zero-based index for column.
@return `NSDate` value of the result set's column.
*/
- (NSDate*)dateForColumnIndex:(int)columnIdx;
/** Result set `NSData` value for column.
This is useful when storing binary data in table (such as image or the like).
@param columnName `NSString` value of the name of the column.
@return `NSData` value of the result set's column.
*/
- (NSData*)dataForColumn:(NSString*)columnName;
/** Result set `NSData` value for column.
@param columnIdx Zero-based index for column.
@return `NSData` value of the result set's column.
*/
- (NSData*)dataForColumnIndex:(int)columnIdx;
/** Result set `(const unsigned char *)` value for column.
@param columnName `NSString` value of the name of the column.
@return `(const unsigned char *)` value of the result set's column.
*/
- (const unsigned char *)UTF8StringForColumnName:(NSString*)columnName;
/** Result set `(const unsigned char *)` value for column.
@param columnIdx Zero-based index for column.
@return `(const unsigned char *)` value of the result set's column.
*/
- (const unsigned char *)UTF8StringForColumnIndex:(int)columnIdx;
/** Result set object for column.
@param columnName `NSString` value of the name of the column.
@return Either `NSNumber`, `NSString`, `NSData`, or `NSNull`. If the column was `NULL`, this returns `[NSNull null]` object.
@see objectForKeyedSubscript:
*/
- (id)objectForColumnName:(NSString*)columnName;
/** Result set object for column.
@param columnIdx Zero-based index for column.
@return Either `NSNumber`, `NSString`, `NSData`, or `NSNull`. If the column was `NULL`, this returns `[NSNull null]` object.
@see objectAtIndexedSubscript:
*/
- (id)objectForColumnIndex:(int)columnIdx;
/** Result set object for column.
This method allows the use of the "boxed" syntax supported in Modern Objective-C. For example, by defining this method, the following syntax is now supported:
id result = rs[@"employee_name"];
This simplified syntax is equivalent to calling:
id result = [rs objectForKeyedSubscript:@"employee_name"];
which is, it turns out, equivalent to calling:
id result = [rs objectForColumnName:@"employee_name"];
@param columnName `NSString` value of the name of the column.
@return Either `NSNumber`, `NSString`, `NSData`, or `NSNull`. If the column was `NULL`, this returns `[NSNull null]` object.
*/
- (id)objectForKeyedSubscript:(NSString *)columnName;
/** Result set object for column.
This method allows the use of the "boxed" syntax supported in Modern Objective-C. For example, by defining this method, the following syntax is now supported:
id result = rs[0];
This simplified syntax is equivalent to calling:
id result = [rs objectForKeyedSubscript:0];
which is, it turns out, equivalent to calling:
id result = [rs objectForColumnName:0];
@param columnIdx Zero-based index for column.
@return Either `NSNumber`, `NSString`, `NSData`, or `NSNull`. If the column was `NULL`, this returns `[NSNull null]` object.
*/
- (id)objectAtIndexedSubscript:(int)columnIdx;
/** Result set `NSData` value for column.
@param columnName `NSString` value of the name of the column.
@return `NSData` value of the result set's column.
@warning If you are going to use this data after you iterate over the next row, or after you close the
result set, make sure to make a copy of the data first (or just use `<dataForColumn:>`/`<dataForColumnIndex:>`)
If you don't, you're going to be in a world of hurt when you try and use the data.
*/
- (NSData*)dataNoCopyForColumn:(NSString*)columnName NS_RETURNS_NOT_RETAINED;
/** Result set `NSData` value for column.
@param columnIdx Zero-based index for column.
@return `NSData` value of the result set's column.
@warning If you are going to use this data after you iterate over the next row, or after you close the
result set, make sure to make a copy of the data first (or just use `<dataForColumn:>`/`<dataForColumnIndex:>`)
If you don't, you're going to be in a world of hurt when you try and use the data.
*/
- (NSData*)dataNoCopyForColumnIndex:(int)columnIdx NS_RETURNS_NOT_RETAINED;
/** Is the column `NULL`?
@param columnIdx Zero-based index for column.
@return `YES` if column is `NULL`; `NO` if not `NULL`.
*/
- (BOOL)columnIndexIsNull:(int)columnIdx;
/** Is the column `NULL`?
@param columnName `NSString` value of the name of the column.
@return `YES` if column is `NULL`; `NO` if not `NULL`.
*/
- (BOOL)columnIsNull:(NSString*)columnName;
/** Returns a dictionary of the row results mapped to case sensitive keys of the column names.
@returns `NSDictionary` of the row results.
@warning The keys to the dictionary are case sensitive of the column names.
*/
- (NSDictionary*)resultDictionary;
/** Returns a dictionary of the row results
@see resultDictionary
@warning **Deprecated**: Please use `<resultDictionary>` instead. Also, beware that `<resultDictionary>` is case sensitive!
*/
- (NSDictionary*)resultDict __attribute__ ((deprecated));
///-----------------------------
/// @name Key value coding magic
///-----------------------------
/** Performs `setValue` to yield support for key value observing.
@param object The object for which the values will be set. This is the key-value-coding compliant object that you might, for example, observe.
*/
- (void)kvcMagic:(id)object;
@end
@@ -0,0 +1,28 @@
//
// DypayDIRSGlobalTimer.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/12.
//
#import <Foundation/Foundation.h>
#import "DypayIRISInterfaceDefines.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSGlobalTimer : NSObject
+ (instancetype)globalTimer;
- (void)addTimer:(id<DypayIRISTimer> _Nullable)timer;
- (void)removeTimer:(id<DypayIRISTimer> _Nullable)timer;
- (void)startTimer;
- (void)stopTimer;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,29 @@
//
// DypayDIRSIdentity.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/13.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSIdentity : DypayDIRSBasicModule<DypayIRISModule>
//for all service
@property (readonly) BOOL isIdentifierAvailable;
@property (readonly, nullable) NSString *clientId;
- (void)setUserIdentifiers:(NSDictionary *)IDs;
- (void)setDeviceIdentifiers:(NSDictionary *)IDs;
- (NSDictionary *)userIdentifiers;
- (NSDictionary *)deviceIdentifiers;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,32 @@
//
// DypayDIRSLogger.h
// DypayDataIRIS
//
// Created by ByteDance on 2023/7/11.
//
#import "DypayDIRSBasicModule.h"
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSConsoleLogger : DypayDIRSBasicModule<DypayIRISModule, DypayIRISLogger>
@end
@interface DypayDIRSLogger : DypayDIRSBasicModule<DypayIRISModule>
- (void)addLogger:(id<DypayIRISLogger>)logger;
- (void)removeLogger:(id<DypayIRISLogger>)logger;
- (void)removeAllLoggers;
- (void)addLog:(id<DypayIRISLog> _Nonnull)log;
- (nonnull NSString *)stringUsingDefaultFormatter:(nonnull id<DypayIRISLog>)log;
@end
NS_ASSUME_NONNULL_END
@@ -0,0 +1,27 @@
//
// DypayDIRSMMapCache.h
// DypayDataIRIS
//
// Created by ByteDance on 2024/3/11.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface DypayDIRSMMapCache : NSObject
@property (nonatomic, assign, readonly) BOOL isMapping;
@property (nonatomic, assign, readonly, nullable) void *object;
- (instancetype)initWithPath:(NSString *)path;
- (BOOL)mmap:(size_t)size;
- (void)munmap;
@end
NS_ASSUME_NONNULL_END

Some files were not shown because too many files have changed in this diff Show More