@qmuse/appwrite-runtime-sdk 1.0.5-dev.1 → 1.0.5-dev.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -199,7 +199,7 @@ export function TodoList() {
199
199
 
200
200
  ## Taro 项目
201
201
 
202
- Taro 项目通过 `createPortableAppwriteClients()` 使用同一套 Runtime API。该方式适用于 Taro H5、支付宝小程序和微信小程序。
202
+ Taro 项目通过 `createQmuseAppwriteRuntime()` 使用同一套 Runtime API,SDK 会在内部创建跨端客户端。该方式适用于 Taro H5、支付宝小程序和微信小程序。
203
203
 
204
204
  ### 1. 配置跨端环境变量
205
205
 
@@ -333,7 +333,6 @@ export const platformStorage = {
333
333
  // src/services/appwrite.ts
334
334
  import { ID, Permission, Query, Role } from 'appwrite';
335
335
  import {
336
- createPortableAppwriteClients,
337
336
  createQmuseAppwriteRuntime,
338
337
  type Models,
339
338
  } from '@qmuse/appwrite-runtime-sdk';
@@ -344,16 +343,11 @@ function getQmuseLoginUserId(): string | null {
344
343
  return null;
345
344
  }
346
345
 
347
- const clients = createPortableAppwriteClients({
348
- fetch: platformFetch,
349
- storage: platformStorage,
350
- });
351
-
352
346
  const runtime = createQmuseAppwriteRuntime({
353
- ...clients,
354
347
  getMuseRuntime: getMuseRuntimeConfig,
355
348
  getQmuseLoginUserId,
356
349
  fetch: platformFetch,
350
+ storage: platformStorage,
357
351
  });
358
352
 
359
353
  export const initAppwrite = runtime.init;
@@ -465,7 +459,7 @@ await deleteQmuseRow({
465
459
  ## 接入约束
466
460
 
467
461
  - 每个应用只创建一个 `createQmuseAppwriteRuntime()` 实例。
468
- - React 应用使用 Appwrite Web SDK 客户端;Taro 应用使用 `createPortableAppwriteClients()`。
462
+ - React 应用向 `createQmuseAppwriteRuntime()` 传入 Appwrite Web SDK 客户端;Taro 应用传入跨端 `fetch` 和 `storage`。
469
463
  - H5、支付宝小程序和微信小程序必须使用相同的 `appId`、`env` 和 `domain` 配置来源。
470
464
  - React 应用的 `getQmuseLoginUserId()` 只返回有效的用户 ID 或 `null`;Taro 应用固定返回 `null`。
471
465
  - 业务代码通过 Runtime 的 CRUD 方法读写数据,不直接拼接 Appwrite HTTP 接口。
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
1
  export { createQmuseAppwriteRuntime } from './runtime';
2
- export { createPortableAppwriteClients } from './portable';
3
- export type { AppwriteAccountLike, AppwriteClientLike, AppwriteError, AppwriteRuntimeConfig, AppwriteRuntimeStorage, AppwriteSession, AppwriteTablesDBLike, AppwriteUser, BusinessRowData, CreateRowInput, DeleteRowInput, GetRowInput, ListRowsInput, Models, QmuseAppwriteClients, QmuseAppwriteRuntimeApi, QmuseAppwriteRuntimeOptions, QmuseEnvironment, QmuseRuntimeContext, PortableAppwriteClientsOptions, UpdateRowInput, } from './types';
2
+ export type { AppwriteAccountLike, AppwriteClientLike, AppwriteError, AppwriteRuntimeConfig, AppwriteRuntimeStorage, AppwriteSession, AppwriteTablesDBLike, AppwriteUser, BusinessRowData, CreateRowInput, DeleteRowInput, GetRowInput, ListRowsInput, Models, QmuseAppwriteClients, QmuseAppwriteRuntimeApi, QmuseAppwriteRuntimeOptions, QmuseEnvironment, QmuseRuntimeContext, UpdateRowInput, } from './types';
package/dist/index.js CHANGED
@@ -1,2 +1 @@
1
- export { createQmuseAppwriteRuntime } from "./runtime";
2
- export { createPortableAppwriteClients } from "./portable";
1
+ export { createQmuseAppwriteRuntime } from "./runtime";
@@ -1,5 +1,5 @@
1
1
  import type { AppwriteAccountLike, AppwriteClientLike, AppwriteTablesDBLike, PortableAppwriteClientsOptions } from './types';
2
- export declare function createPortableAppwriteClients(options: PortableAppwriteClientsOptions): {
2
+ export declare function createPortableAppwriteClientsInternal(options: PortableAppwriteClientsOptions): {
3
3
  client: AppwriteClientLike;
4
4
  account: AppwriteAccountLike;
5
5
  tablesDB: AppwriteTablesDBLike;
package/dist/portable.js CHANGED
@@ -369,7 +369,7 @@ var PortableTablesDB = /*#__PURE__*/function () {
369
369
  }]);
370
370
  return PortableTablesDB;
371
371
  }();
372
- export function createPortableAppwriteClients(options) {
372
+ export function createPortableAppwriteClientsInternal(options) {
373
373
  var client = new PortableAppwriteClient(options);
374
374
  return {
375
375
  client: client,
@@ -1,4 +1,4 @@
1
- import type { AppwriteUser, QmuseAppwriteRuntimeOptions } from '../types';
1
+ import type { AppwriteUser, ResolvedQmuseAppwriteRuntimeOptions } from '../types';
2
2
  export declare class AppwriteSessionCoordinator {
3
3
  private readonly options;
4
4
  private readonly request;
@@ -6,7 +6,7 @@ export declare class AppwriteSessionCoordinator {
6
6
  private initPromise;
7
7
  private sessionSyncPromise;
8
8
  private refreshPromise;
9
- constructor(options: QmuseAppwriteRuntimeOptions, request: typeof globalThis.fetch);
9
+ constructor(options: ResolvedQmuseAppwriteRuntimeOptions, request: typeof globalThis.fetch);
10
10
  init(): Promise<void>;
11
11
  getDatabaseId(): Promise<string>;
12
12
  getCurrentUser(): Promise<AppwriteUser>;
@@ -1,4 +1,4 @@
1
- import type { QmuseAppwriteRuntimeApi, QmuseAppwriteRuntimeOptions } from '../types';
1
+ import type { QmuseAppwriteRuntimeApi, ResolvedQmuseAppwriteRuntimeOptions } from '../types';
2
2
  export declare class QmuseAppwriteRuntime implements QmuseAppwriteRuntimeApi {
3
3
  private readonly options;
4
4
  readonly init: QmuseAppwriteRuntimeApi['init'];
@@ -12,7 +12,7 @@ export declare class QmuseAppwriteRuntime implements QmuseAppwriteRuntimeApi {
12
12
  readonly deleteRow: QmuseAppwriteRuntimeApi['deleteRow'];
13
13
  private readonly session;
14
14
  private readonly auditReporter;
15
- constructor(options: QmuseAppwriteRuntimeOptions);
15
+ constructor(options: ResolvedQmuseAppwriteRuntimeOptions);
16
16
  private getClientsInternal;
17
17
  private listRowsInternal;
18
18
  private getRowInternal;
package/dist/runtime.js CHANGED
@@ -1,4 +1,17 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
1
2
  import { QmuseAppwriteRuntime } from "./runtime/QmuseAppwriteRuntime";
3
+ import { createPortableAppwriteClientsInternal } from "./portable";
4
+ function resolveRuntimeOptions(options) {
5
+ if (options.client && options.account && options.tablesDB) {
6
+ return options;
7
+ }
8
+ var clients = createPortableAppwriteClientsInternal({
9
+ fetch: options.fetch,
10
+ storage: options.storage,
11
+ storageKeyPrefix: options.storageKeyPrefix
12
+ });
13
+ return _objectSpread(_objectSpread({}, options), clients);
14
+ }
2
15
  export function createQmuseAppwriteRuntime(options) {
3
- return new QmuseAppwriteRuntime(options);
16
+ return new QmuseAppwriteRuntime(resolveRuntimeOptions(options));
4
17
  }
package/dist/types.d.ts CHANGED
@@ -80,12 +80,27 @@ export interface AppwriteTablesDBLike {
80
80
  rowId: string;
81
81
  }): Promise<unknown>;
82
82
  }
83
- export interface QmuseAppwriteRuntimeOptions {
83
+ interface QmuseAppwriteRuntimeBaseOptions {
84
+ getMuseRuntime(): QmuseRuntimeContext;
85
+ getQmuseLoginUserId(): string | null;
86
+ }
87
+ interface QmuseAppwriteInjectedClientsOptions extends QmuseAppwriteRuntimeBaseOptions {
88
+ client: AppwriteClientLike;
89
+ account: AppwriteAccountLike;
90
+ tablesDB: AppwriteTablesDBLike;
91
+ fetch?: typeof globalThis.fetch;
92
+ storage?: never;
93
+ }
94
+ interface QmuseAppwritePortableRuntimeOptions extends QmuseAppwriteRuntimeBaseOptions, PortableAppwriteClientsOptions {
95
+ client?: never;
96
+ account?: never;
97
+ tablesDB?: never;
98
+ }
99
+ export type QmuseAppwriteRuntimeOptions = QmuseAppwriteInjectedClientsOptions | QmuseAppwritePortableRuntimeOptions;
100
+ export interface ResolvedQmuseAppwriteRuntimeOptions extends QmuseAppwriteRuntimeBaseOptions {
84
101
  client: AppwriteClientLike;
85
102
  account: AppwriteAccountLike;
86
103
  tablesDB: AppwriteTablesDBLike;
87
- getMuseRuntime(): QmuseRuntimeContext;
88
- getQmuseLoginUserId(): string | null;
89
104
  fetch?: typeof globalThis.fetch;
90
105
  }
91
106
  export interface QmuseAppwriteClients {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qmuse/appwrite-runtime-sdk",
3
- "version": "1.0.5-dev.1",
3
+ "version": "1.0.5-dev.2",
4
4
  "description": "QMuse Appwrite browser runtime SDK",
5
5
  "repository": {
6
6
  "type": "git",