@thinkingdifferently/core 1.0.3-beta.3 → 1.1.0

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/dist/index.d.mts CHANGED
@@ -11,11 +11,38 @@ declare class TDClient {
11
11
  request(method: "POST" | "GET" | "PATCH" | "DELETE", body?: any): Promise<any>;
12
12
  }
13
13
 
14
+ type Operator = "=" | "!=" | ">" | "<" | ">=" | "<=" | "in" | "contains";
15
+ type Filter = {
16
+ field: string;
17
+ operator: Operator;
18
+ value: unknown;
19
+ };
20
+ type Query = {
21
+ collection: string;
22
+ filters: Filter[];
23
+ limit: number | null;
24
+ sort: {
25
+ field: string;
26
+ direction: "asc" | "desc";
27
+ } | null;
28
+ };
29
+ declare class QueryBuilder {
30
+ private query;
31
+ private client;
32
+ constructor(collection: string, client: TDClient);
33
+ where(field: string, operator: Operator, value: unknown): this;
34
+ limit(count: number): this;
35
+ sort(field: string, direction: "asc" | "desc"): this;
36
+ get<T = any>(): Promise<T[]>;
37
+ count(): Promise<number>;
38
+ toJSON(): Query;
39
+ }
40
+
14
41
  declare class ThinkingDifferently {
15
42
  private client;
16
43
  constructor(config: SDKConfig);
44
+ collection(name: string): QueryBuilder;
17
45
  insert(key: string, data: any): Promise<any>;
18
- get(key: string, options?: GetOptions): Promise<any>;
19
46
  update(key: string, id: string, data: Record<string, any>): Promise<any>;
20
47
  delete(key: string, id: string): Promise<any>;
21
48
  }
package/dist/index.d.ts CHANGED
@@ -11,11 +11,38 @@ declare class TDClient {
11
11
  request(method: "POST" | "GET" | "PATCH" | "DELETE", body?: any): Promise<any>;
12
12
  }
13
13
 
14
+ type Operator = "=" | "!=" | ">" | "<" | ">=" | "<=" | "in" | "contains";
15
+ type Filter = {
16
+ field: string;
17
+ operator: Operator;
18
+ value: unknown;
19
+ };
20
+ type Query = {
21
+ collection: string;
22
+ filters: Filter[];
23
+ limit: number | null;
24
+ sort: {
25
+ field: string;
26
+ direction: "asc" | "desc";
27
+ } | null;
28
+ };
29
+ declare class QueryBuilder {
30
+ private query;
31
+ private client;
32
+ constructor(collection: string, client: TDClient);
33
+ where(field: string, operator: Operator, value: unknown): this;
34
+ limit(count: number): this;
35
+ sort(field: string, direction: "asc" | "desc"): this;
36
+ get<T = any>(): Promise<T[]>;
37
+ count(): Promise<number>;
38
+ toJSON(): Query;
39
+ }
40
+
14
41
  declare class ThinkingDifferently {
15
42
  private client;
16
43
  constructor(config: SDKConfig);
44
+ collection(name: string): QueryBuilder;
17
45
  insert(key: string, data: any): Promise<any>;
18
- get(key: string, options?: GetOptions): Promise<any>;
19
46
  update(key: string, id: string, data: Record<string, any>): Promise<any>;
20
47
  delete(key: string, id: string): Promise<any>;
21
48
  }
package/dist/index.js CHANGED
@@ -65,12 +65,110 @@ var TDClient = class {
65
65
  }
66
66
  };
67
67
 
68
+ // src/QueryBuilder.ts
69
+ var QueryBuilder = class {
70
+ constructor(collection, client) {
71
+ this.client = client;
72
+ this.query = {
73
+ collection,
74
+ filters: [],
75
+ limit: null,
76
+ sort: null
77
+ };
78
+ }
79
+ where(field, operator, value) {
80
+ if (operator === "in" && !Array.isArray(value)) {
81
+ throw new Error("Value must be an array for 'in' operator");
82
+ }
83
+ if (!field.trim()) {
84
+ throw new Error("Field name cannot be empty");
85
+ }
86
+ this.query.filters.push({ field, operator, value });
87
+ return this;
88
+ }
89
+ limit(count) {
90
+ if (!Number.isInteger(count) || count <= 0) {
91
+ throw new Error("Limit must be a positive integer");
92
+ }
93
+ this.query.limit = count;
94
+ return this;
95
+ }
96
+ sort(field, direction) {
97
+ if (!field.trim()) {
98
+ throw new Error("Field name cannot be empty");
99
+ }
100
+ this.query.sort = { field, direction };
101
+ return this;
102
+ }
103
+ // build() {
104
+ // return this.query;
105
+ // }
106
+ async get() {
107
+ console.log("\n================ GET REQUEST ================");
108
+ console.log("[SDK] Final Query:", this.query);
109
+ try {
110
+ const response = await this.client.request(
111
+ "POST",
112
+ this.query
113
+ );
114
+ console.log("[SDK] Raw Response:", response);
115
+ if (!Array.isArray(response.data)) {
116
+ throw new Error("Invalid response format");
117
+ }
118
+ const parsed = response.data.map(
119
+ (item) => item.data
120
+ );
121
+ console.log("[SDK] Parsed Data:", parsed);
122
+ return parsed;
123
+ } catch (error) {
124
+ console.error("[SDK] GET ERROR");
125
+ console.error(error);
126
+ throw error;
127
+ }
128
+ }
129
+ //to do writing the count method for the query builder
130
+ //the conditions are specified , so now the count method should return the number of documents that match the specified conditions in the query builder
131
+ //means count will first get the data based on the filters and then return the length of the data array as the count of matching documents
132
+ async count() {
133
+ console.log("\n================ COUNT REQUEST ================");
134
+ console.log("[SDK] Final Query for Count:", this.query);
135
+ try {
136
+ const response = await this.client.request(
137
+ "POST",
138
+ {
139
+ ...this.query,
140
+ countOnly: true
141
+ // Indicate we only want the count
142
+ }
143
+ );
144
+ console.log("[SDK] Count Response:", response);
145
+ if (typeof response.count !== "number") {
146
+ throw new Error("Invalid count response from API");
147
+ }
148
+ return response.count;
149
+ } catch (error) {
150
+ console.error("[SDK] COUNT ERROR");
151
+ console.error(error);
152
+ throw error;
153
+ }
154
+ }
155
+ toJSON() {
156
+ return structuredClone(this.query);
157
+ }
158
+ };
159
+
68
160
  // src/index.ts
69
161
  var ThinkingDifferently = class {
70
162
  constructor(config) {
71
163
  console.log("[ThinkingDifferently SDK] Initializing SDK");
72
164
  this.client = new TDClient(config.apiKey);
73
165
  }
166
+ collection(name) {
167
+ return new QueryBuilder(
168
+ name,
169
+ this.client
170
+ );
171
+ }
74
172
  async insert(key, data) {
75
173
  console.log("\n================ INSERT REQUEST ================");
76
174
  console.log("[SDK] Collection Key:", key);
@@ -122,30 +220,6 @@ var ThinkingDifferently = class {
122
220
  throw error;
123
221
  }
124
222
  }
125
- async get(key, options) {
126
- console.log("\n================ GET REQUEST ================");
127
- console.log("[SDK] Collection Key:", key);
128
- console.log("[SDK] Options:", options);
129
- try {
130
- const response = await this.client.request(
131
- "GET",
132
- {
133
- key,
134
- ...options
135
- }
136
- );
137
- console.log("[SDK] Raw Response:", response);
138
- const parsed = response.data.map(
139
- (item) => item.data
140
- );
141
- console.log("[SDK] Parsed Data:", parsed);
142
- return parsed;
143
- } catch (error) {
144
- console.error("[SDK] GET ERROR");
145
- console.error(error);
146
- throw error;
147
- }
148
- }
149
223
  async update(key, id, data) {
150
224
  console.log("\n================ UPDATE REQUEST ================");
151
225
  console.log("[SDK] Collection Key:", key);
package/dist/index.mjs CHANGED
@@ -28,12 +28,110 @@ var TDClient = class {
28
28
  }
29
29
  };
30
30
 
31
+ // src/QueryBuilder.ts
32
+ var QueryBuilder = class {
33
+ constructor(collection, client) {
34
+ this.client = client;
35
+ this.query = {
36
+ collection,
37
+ filters: [],
38
+ limit: null,
39
+ sort: null
40
+ };
41
+ }
42
+ where(field, operator, value) {
43
+ if (operator === "in" && !Array.isArray(value)) {
44
+ throw new Error("Value must be an array for 'in' operator");
45
+ }
46
+ if (!field.trim()) {
47
+ throw new Error("Field name cannot be empty");
48
+ }
49
+ this.query.filters.push({ field, operator, value });
50
+ return this;
51
+ }
52
+ limit(count) {
53
+ if (!Number.isInteger(count) || count <= 0) {
54
+ throw new Error("Limit must be a positive integer");
55
+ }
56
+ this.query.limit = count;
57
+ return this;
58
+ }
59
+ sort(field, direction) {
60
+ if (!field.trim()) {
61
+ throw new Error("Field name cannot be empty");
62
+ }
63
+ this.query.sort = { field, direction };
64
+ return this;
65
+ }
66
+ // build() {
67
+ // return this.query;
68
+ // }
69
+ async get() {
70
+ console.log("\n================ GET REQUEST ================");
71
+ console.log("[SDK] Final Query:", this.query);
72
+ try {
73
+ const response = await this.client.request(
74
+ "POST",
75
+ this.query
76
+ );
77
+ console.log("[SDK] Raw Response:", response);
78
+ if (!Array.isArray(response.data)) {
79
+ throw new Error("Invalid response format");
80
+ }
81
+ const parsed = response.data.map(
82
+ (item) => item.data
83
+ );
84
+ console.log("[SDK] Parsed Data:", parsed);
85
+ return parsed;
86
+ } catch (error) {
87
+ console.error("[SDK] GET ERROR");
88
+ console.error(error);
89
+ throw error;
90
+ }
91
+ }
92
+ //to do writing the count method for the query builder
93
+ //the conditions are specified , so now the count method should return the number of documents that match the specified conditions in the query builder
94
+ //means count will first get the data based on the filters and then return the length of the data array as the count of matching documents
95
+ async count() {
96
+ console.log("\n================ COUNT REQUEST ================");
97
+ console.log("[SDK] Final Query for Count:", this.query);
98
+ try {
99
+ const response = await this.client.request(
100
+ "POST",
101
+ {
102
+ ...this.query,
103
+ countOnly: true
104
+ // Indicate we only want the count
105
+ }
106
+ );
107
+ console.log("[SDK] Count Response:", response);
108
+ if (typeof response.count !== "number") {
109
+ throw new Error("Invalid count response from API");
110
+ }
111
+ return response.count;
112
+ } catch (error) {
113
+ console.error("[SDK] COUNT ERROR");
114
+ console.error(error);
115
+ throw error;
116
+ }
117
+ }
118
+ toJSON() {
119
+ return structuredClone(this.query);
120
+ }
121
+ };
122
+
31
123
  // src/index.ts
32
124
  var ThinkingDifferently = class {
33
125
  constructor(config) {
34
126
  console.log("[ThinkingDifferently SDK] Initializing SDK");
35
127
  this.client = new TDClient(config.apiKey);
36
128
  }
129
+ collection(name) {
130
+ return new QueryBuilder(
131
+ name,
132
+ this.client
133
+ );
134
+ }
37
135
  async insert(key, data) {
38
136
  console.log("\n================ INSERT REQUEST ================");
39
137
  console.log("[SDK] Collection Key:", key);
@@ -85,30 +183,6 @@ var ThinkingDifferently = class {
85
183
  throw error;
86
184
  }
87
185
  }
88
- async get(key, options) {
89
- console.log("\n================ GET REQUEST ================");
90
- console.log("[SDK] Collection Key:", key);
91
- console.log("[SDK] Options:", options);
92
- try {
93
- const response = await this.client.request(
94
- "GET",
95
- {
96
- key,
97
- ...options
98
- }
99
- );
100
- console.log("[SDK] Raw Response:", response);
101
- const parsed = response.data.map(
102
- (item) => item.data
103
- );
104
- console.log("[SDK] Parsed Data:", parsed);
105
- return parsed;
106
- } catch (error) {
107
- console.error("[SDK] GET ERROR");
108
- console.error(error);
109
- throw error;
110
- }
111
- }
112
186
  async update(key, id, data) {
113
187
  console.log("\n================ UPDATE REQUEST ================");
114
188
  console.log("[SDK] Collection Key:", key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thinkingdifferently/core",
3
- "version": "1.0.3-beta.3",
3
+ "version": "1.1.0",
4
4
  "description": "Official SDK for Thinking Differently API",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",