Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
"name": "alicloud-tablestore",
"type": "module",
"version": "0.1.0",
"description": "Alicloud Tablestore SDK for Node.js",
"author": "Kevin Cui <bh@bugs.cc>",
"license": "MIT",
"keywords": [
"alicloud",
"tablestore",
"ots"
],
"exports": {
".": {
"types": "./dist/index.d.mts",
Expand Down
9 changes: 9 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { ClientConfig } from "./type";
import { Request } from "./request";

export class Client {
public request: Request;
public constructor(public readonly config: ClientConfig) {
this.request = new Request(config);
}
}
11 changes: 6 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
export {
Client,
} from "./client";

export {
OTS_API_NAME,
} from "./const";

export { Basic } from "./operator/basic";

export {
BatchGetRow,
type BatchGetRowData,
Expand Down Expand Up @@ -86,6 +88,7 @@ export {
type Filter,
FilterType,
type LogicalOperator,
OperationType,
type ReturnContent,
ReturnType,
RowExistenceExpectation,
Expand All @@ -109,9 +112,7 @@ export {
export { Request } from "./request";

export {
type OperatorConfig,
type ClientConfig,
type OTSApiName,
type RequestConfig,
type RequestFactory,
type RequestOptions,
} from "./type";
17 changes: 0 additions & 17 deletions src/operator/basic.ts

This file was deleted.

10 changes: 4 additions & 6 deletions src/operator/batch-get-row.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { Client } from "../client";
import type { ConsumedCapacity, Error, Filter, TimeRange } from "../pb/type";
import type { PlainBufferCell, PlainBufferRow } from "../plainbuffer";
import type { OperatorConfig } from "../type";
import { Buffer } from "node:buffer";
import { buildFilter } from "../builder/filter";
import { OTS_API_NAME } from "../const";
import { builder } from "../pb/builder";
import { decodePlainBuffer, encodePlainBuffer } from "../plainbuffer";
import { fixPlainBufferCellType } from "../utils";
import { Basic } from "./basic";

export const ProtoBatchGetRowRequest = builder.lookupType("ots.BatchGetRowRequest");
export const ProtoBatchGetRowResponse = builder.lookupType("ots.BatchGetRowResponse");
Expand Down Expand Up @@ -45,9 +44,8 @@ export interface BatchGetRowResponse {
tables: Array<TableInBatchGetRowResponse>;
}

export class BatchGetRow extends Basic {
public constructor(config: OperatorConfig) {
super(config);
export class BatchGetRow {
public constructor(private readonly client: Client) {
}

public static async builder(options: BatchGetRowData) {
Expand Down Expand Up @@ -97,7 +95,7 @@ export class BatchGetRow extends Basic {

public async do(data: BatchGetRowData) {
const body = await BatchGetRow.builder(data);
return await this.request.do({
return await this.client.request.do({
apiName: OTS_API_NAME.BatchGetRow,
body,
});
Expand Down
10 changes: 4 additions & 6 deletions src/operator/batch-write-row.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Client } from "../client";
import type { Condition, ConsumedCapacity, Error, ReturnContent } from "../pb/type";
import type { PlainBufferCell, PlainBufferRow } from "../plainbuffer";
import type { OperatorConfig } from "../type";
import type { UpdateRowAttributeColumns } from "./update-row";
import { Buffer } from "node:buffer";
import { buildFilter } from "../builder/filter";
Expand All @@ -9,7 +9,6 @@ import { builder } from "../pb/builder";
import { OperationType, RowExistenceExpectation } from "../pb/type";
import { decodePlainBuffer, encodePlainBuffer } from "../plainbuffer";
import { fixPlainBufferCellType } from "../utils";
import { Basic } from "./basic";
import { UpdateRow } from "./update-row";

export const ProtoBatchWriteRowRequest = builder.lookupType("ots.BatchWriteRowRequest");
Expand Down Expand Up @@ -62,9 +61,8 @@ export interface BatchWriteRowResponse {
tables: Array<TableInBatchWriteRowResponse>;
}

export class BatchWriteRow extends Basic {
public constructor(config: OperatorConfig) {
super(config);
export class BatchWriteRow {
public constructor(private readonly client: Client) {
}

public static async builder(options: BatchWriteRowData) {
Expand Down Expand Up @@ -111,7 +109,7 @@ export class BatchWriteRow extends Basic {

public async do(data: BatchWriteRowData) {
const body = await BatchWriteRow.builder(data);
return await this.request.do({
return await this.client.request.do({
apiName: OTS_API_NAME.BatchWriteRow,
body,
});
Expand Down
10 changes: 4 additions & 6 deletions src/operator/delete-row.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type { Client } from "../client";
import type { Condition, ConsumedCapacity, ReturnContent } from "../pb/type";
import type { PlainBufferCell, PlainBufferRow } from "../plainbuffer";
import type { OperatorConfig } from "../type";
import { Buffer } from "node:buffer";
import { buildFilter } from "../builder/filter";
import { OTS_API_NAME } from "../const";
import { builder } from "../pb/builder";
import { RowExistenceExpectation } from "../pb/type";
import { decodePlainBuffer, encodePlainBuffer } from "../plainbuffer";
import { fixPlainBufferCellType } from "../utils";
import { Basic } from "./basic";

export const ProtoDeleteRowRequest = builder.lookupType("ots.DeleteRowRequest");
export const ProtoDeleteRowResponse = builder.lookupType("ots.DeleteRowResponse");
Expand All @@ -26,9 +25,8 @@ export interface DeleteRowResponse {
row: Array<PlainBufferRow> | null;
}

export class DeleteRow extends Basic {
public constructor(config: OperatorConfig) {
super(config);
export class DeleteRow {
public constructor(private readonly client: Client) {
}

public static async builder(options: DeleteRowData) {
Expand Down Expand Up @@ -66,7 +64,7 @@ export class DeleteRow extends Basic {

public async do(data: DeleteRowData) {
const body = await DeleteRow.builder(data);
return await this.request.do({
return await this.client.request.do({
apiName: OTS_API_NAME.DeleteRow,
body,
});
Expand Down
10 changes: 4 additions & 6 deletions src/operator/get-range.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { Client } from "../client";
import type { ConsumedCapacity, Direction, Filter, TimeRange } from "../pb/type";
import type { PlainBufferCell, PlainBufferRow } from "../plainbuffer";
import type { OperatorConfig } from "../type";
import { Buffer } from "node:buffer";
import { buildFilter } from "../builder/filter";
import { OTS_API_NAME } from "../const";
import { builder } from "../pb/builder";
import { decodePlainBuffer, encodePlainBuffer } from "../plainbuffer";
import { fixPlainBufferCellType } from "../utils";
import { Basic } from "./basic";

export const ProtoGetRangeRequest = builder.lookupType("ots.GetRangeRequest");
export const ProtoGetRangeResponse = builder.lookupType("ots.GetRangeResponse");
Expand All @@ -32,9 +31,8 @@ export interface GetRangeResponse {
nextStartPrimaryKey: PlainBufferRow | null;
}

export class GetRange extends Basic {
public constructor(config: OperatorConfig) {
super(config);
export class GetRange {
public constructor(private readonly client: Client) {
}

public static async builder(options: GetRangeData) {
Expand Down Expand Up @@ -88,7 +86,7 @@ export class GetRange extends Basic {

public async do(data: GetRangeData) {
const body = await GetRange.builder(data);
return await this.request.do({
return await this.client.request.do({
apiName: OTS_API_NAME.GetRange,
body,
});
Expand Down
10 changes: 4 additions & 6 deletions src/operator/get-row.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { Client } from "../client";
import type { ConsumedCapacity, Filter, TimeRange } from "../pb/type";
import type { PlainBufferCell, PlainBufferRow } from "../plainbuffer";
import type { OperatorConfig } from "../type";
import { Buffer } from "node:buffer";
import { buildFilter } from "../builder/filter";
import { OTS_API_NAME } from "../const";
import { builder } from "../pb/builder";
import { decodePlainBuffer, encodePlainBuffer } from "../plainbuffer";
import { fixPlainBufferCellType } from "../utils";
import { Basic } from "./basic";

export const ProtoGetRowRequest = builder.lookupType("ots.GetRowRequest");
export const ProtoGetRowResponse = builder.lookupType("ots.GetRowResponse");
Expand All @@ -31,9 +30,8 @@ export interface GetRowResponse {
nextToken: ArrayBuffer | null; // Tablestore currently not supported
}

export class GetRow extends Basic {
public constructor(config: OperatorConfig) {
super(config);
export class GetRow {
public constructor(private readonly client: Client) {
}

public static async builder(options: GetRowData) {
Expand Down Expand Up @@ -82,7 +80,7 @@ export class GetRow extends Basic {

public async do(data: GetRowData) {
const body = await GetRow.builder(data);
return await this.request.do({
return await this.client.request.do({
apiName: OTS_API_NAME.GetRow,
body,
});
Expand Down
10 changes: 4 additions & 6 deletions src/operator/put-row.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type { Client } from "../client";
import type { Condition, ConsumedCapacity, ReturnContent } from "../pb/type";
import type { PlainBufferCell, PlainBufferRow } from "../plainbuffer";
import type { OperatorConfig } from "../type";
import { Buffer } from "node:buffer";
import { buildFilter } from "../builder/filter";
import { OTS_API_NAME } from "../const";
import { builder } from "../pb/builder";
import { RowExistenceExpectation } from "../pb/type";
import { decodePlainBuffer, encodePlainBuffer } from "../plainbuffer";
import { fixPlainBufferCellType } from "../utils";
import { Basic } from "./basic";

export const ProtoPutRowRequest = builder.lookupType("ots.PutRowRequest");
export const ProtoPutRowResponse = builder.lookupType("ots.PutRowResponse");
Expand All @@ -26,9 +25,8 @@ export interface PutRowResponse {
consumed: ConsumedCapacity;
row: Array<PlainBufferRow> | null;
}
export class PutRow extends Basic {
public constructor(config: OperatorConfig) {
super(config);
export class PutRow {
public constructor(private readonly client: Client) {
}

public static async builder(options: PutRowData) {
Expand Down Expand Up @@ -65,7 +63,7 @@ export class PutRow extends Basic {

public async do(data: PutRowData) {
const body = await PutRow.builder(data);
return await this.request.do({
return await this.client.request.do({
apiName: OTS_API_NAME.PutRow,
body,
});
Expand Down
10 changes: 4 additions & 6 deletions src/operator/update-row.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import type { Client } from "../client";
import type { Condition, ConsumedCapacity, ReturnContent } from "../pb/type";
import type { PlainBufferCell, PlainBufferRow } from "../plainbuffer";
import type { OperatorConfig } from "../type";
import { Buffer } from "node:buffer";
import { buildFilter } from "../builder/filter";
import { OTS_API_NAME } from "../const";
import { builder } from "../pb/builder";
import { RowExistenceExpectation } from "../pb/type";
import { CellOp, decodePlainBuffer, encodePlainBuffer } from "../plainbuffer";
import { fixPlainBufferCellType } from "../utils";
import { Basic } from "./basic";

export const ProtoUpdateRowRequest = builder.lookupType("ots.UpdateRowRequest");
export const ProtoUpdateRowResponse = builder.lookupType("ots.UpdateRowResponse");
Expand All @@ -33,9 +32,8 @@ export interface UpdateRowResponse {
row: Array<PlainBufferRow> | null;
}

export class UpdateRow extends Basic {
public constructor(config: OperatorConfig) {
super(config);
export class UpdateRow {
public constructor(private readonly client: Client) {
}

public static async builder(options: UpdateRowData) {
Expand Down Expand Up @@ -69,7 +67,7 @@ export class UpdateRow extends Basic {

public async do(data: UpdateRowData) {
const body = await UpdateRow.builder(data);
return await this.request.do({
return await this.client.request.do({
apiName: OTS_API_NAME.UpdateRow,
body,
});
Expand Down
4 changes: 2 additions & 2 deletions src/request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OTSApiName, RequestConfig, RequestOptions } from "./type";
import type { ClientConfig, OTSApiName, RequestOptions } from "./type";
import { createHash, createHmac } from "node:crypto";
import ky from "ky";
import { API_VERSION, H_OTS_ACCESS_KEY_ID, H_OTS_API_VERSION, H_OTS_CONTENT_MD5, H_OTS_DATE, H_OTS_INSTANCE_NAME, H_OTS_PREFIX, H_OTS_SIGNATURE, USER_AGENT } from "./const";
Expand All @@ -9,7 +9,7 @@ const DEFAULT_REQUEST_OPTIONS = {
};

export class Request {
public constructor(private readonly config: RequestConfig) {
public constructor(private readonly config: ClientConfig) {
}

public async do(options: RequestOptions): Promise<Uint8Array> {
Expand Down
10 changes: 1 addition & 9 deletions src/type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { OTS_API_NAME } from "./const";

export interface RequestConfig {
export interface ClientConfig {
endpoint: string;
accessKeyID: string;
accessKeySecret: string;
Expand All @@ -13,12 +13,4 @@ export interface RequestOptions {
headers?: Record<string, string>;
}

export interface RequestFactory {
do: (options: RequestOptions) => Promise<any>;
}

export interface OperatorConfig extends RequestConfig {
request?: RequestFactory;
}

export type OTSApiName = keyof typeof OTS_API_NAME;
Loading