@payez/next-mvp 4.0.26 → 4.0.27
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/vibe/generic.d.ts +14 -21
- package/dist/vibe/generic.js +13 -11
- package/package.json +1 -1
- package/src/vibe/generic.ts +24 -22
package/dist/vibe/generic.d.ts
CHANGED
|
@@ -75,16 +75,17 @@ export interface VibeDocumentWrapper {
|
|
|
75
75
|
* Vibe returns documents with a wrapper where actual data is a JSON string.
|
|
76
76
|
*
|
|
77
77
|
* @param doc - Raw Vibe document (wrapper format)
|
|
78
|
-
* @returns Unwrapped document with
|
|
78
|
+
* @returns Unwrapped document with schema fields only.
|
|
79
|
+
* Storage-layer document_id preserved as _vibe_doc_id for update/delete paths.
|
|
80
|
+
* See PayEz-Core/docs/vibe-primary-key-standard.md
|
|
79
81
|
*
|
|
80
82
|
* @example
|
|
81
|
-
* const raw = { document_id: 123, data: '{"name":"John","email":"john@example.com"}' };
|
|
83
|
+
* const raw = { document_id: 123, data: '{"user_id":15,"name":"John","email":"john@example.com"}' };
|
|
82
84
|
* const unwrapped = unwrapVibeDocument(raw);
|
|
83
|
-
* // => {
|
|
85
|
+
* // => { user_id: 15, name: 'John', email: 'john@example.com', _vibe_doc_id: 123 }
|
|
84
86
|
*/
|
|
85
87
|
export declare function unwrapVibeDocument<T extends Record<string, unknown> = Record<string, unknown>>(doc: VibeDocumentWrapper | Record<string, unknown> | null | undefined): (T & {
|
|
86
|
-
|
|
87
|
-
document_id: number;
|
|
88
|
+
_vibe_doc_id?: number;
|
|
88
89
|
}) | null;
|
|
89
90
|
/**
|
|
90
91
|
* Extract and unwrap array of documents from Vibe response.
|
|
@@ -98,8 +99,7 @@ export declare function unwrapVibeDocument<T extends Record<string, unknown> = R
|
|
|
98
99
|
* const resumes = extractVibeDocuments(data);
|
|
99
100
|
*/
|
|
100
101
|
export declare function extractVibeDocuments<T extends Record<string, unknown> = Record<string, unknown>>(responseData: unknown): Array<T & {
|
|
101
|
-
|
|
102
|
-
document_id: number;
|
|
102
|
+
_vibe_doc_id?: number;
|
|
103
103
|
}>;
|
|
104
104
|
/**
|
|
105
105
|
* Generic table delegate for dynamic collection/table access.
|
|
@@ -114,8 +114,7 @@ export declare class GenericTableDelegate<T extends Record<string, unknown> = Re
|
|
|
114
114
|
* Find multiple records with optional filtering and pagination.
|
|
115
115
|
*/
|
|
116
116
|
findMany(options?: FindManyOptions<T>): Promise<FindManyResult<T & {
|
|
117
|
-
|
|
118
|
-
document_id: number;
|
|
117
|
+
_vibe_doc_id?: number;
|
|
119
118
|
}>>;
|
|
120
119
|
/**
|
|
121
120
|
* Find a single record by ID.
|
|
@@ -126,8 +125,7 @@ export declare class GenericTableDelegate<T extends Record<string, unknown> = Re
|
|
|
126
125
|
id: number;
|
|
127
126
|
};
|
|
128
127
|
}): Promise<T & {
|
|
129
|
-
|
|
130
|
-
document_id: number;
|
|
128
|
+
_vibe_doc_id?: number;
|
|
131
129
|
}>;
|
|
132
130
|
/**
|
|
133
131
|
* Find a single record by ID, returns null if not found.
|
|
@@ -137,15 +135,13 @@ export declare class GenericTableDelegate<T extends Record<string, unknown> = Re
|
|
|
137
135
|
id: number;
|
|
138
136
|
};
|
|
139
137
|
}): Promise<(T & {
|
|
140
|
-
|
|
141
|
-
document_id: number;
|
|
138
|
+
_vibe_doc_id?: number;
|
|
142
139
|
}) | null>;
|
|
143
140
|
/**
|
|
144
141
|
* Find the first record matching the filter.
|
|
145
142
|
*/
|
|
146
143
|
findFirst(options?: FindManyOptions<T>): Promise<(T & {
|
|
147
|
-
|
|
148
|
-
document_id: number;
|
|
144
|
+
_vibe_doc_id?: number;
|
|
149
145
|
}) | null>;
|
|
150
146
|
/**
|
|
151
147
|
* Create a new record.
|
|
@@ -153,8 +149,7 @@ export declare class GenericTableDelegate<T extends Record<string, unknown> = Re
|
|
|
153
149
|
create(options: {
|
|
154
150
|
data: Partial<T>;
|
|
155
151
|
}): Promise<T & {
|
|
156
|
-
|
|
157
|
-
document_id: number;
|
|
152
|
+
_vibe_doc_id?: number;
|
|
158
153
|
}>;
|
|
159
154
|
/**
|
|
160
155
|
* Update an existing record by ID.
|
|
@@ -165,8 +160,7 @@ export declare class GenericTableDelegate<T extends Record<string, unknown> = Re
|
|
|
165
160
|
};
|
|
166
161
|
data: Partial<T>;
|
|
167
162
|
}): Promise<T & {
|
|
168
|
-
|
|
169
|
-
document_id: number;
|
|
163
|
+
_vibe_doc_id?: number;
|
|
170
164
|
}>;
|
|
171
165
|
/**
|
|
172
166
|
* Delete a record by ID (soft delete).
|
|
@@ -176,8 +170,7 @@ export declare class GenericTableDelegate<T extends Record<string, unknown> = Re
|
|
|
176
170
|
id: number;
|
|
177
171
|
};
|
|
178
172
|
}): Promise<T & {
|
|
179
|
-
|
|
180
|
-
document_id: number;
|
|
173
|
+
_vibe_doc_id?: number;
|
|
181
174
|
}>;
|
|
182
175
|
/**
|
|
183
176
|
* Count records matching the filter.
|
package/dist/vibe/generic.js
CHANGED
|
@@ -78,18 +78,20 @@ function vibeGridPath(collection, table) {
|
|
|
78
78
|
* Vibe returns documents with a wrapper where actual data is a JSON string.
|
|
79
79
|
*
|
|
80
80
|
* @param doc - Raw Vibe document (wrapper format)
|
|
81
|
-
* @returns Unwrapped document with
|
|
81
|
+
* @returns Unwrapped document with schema fields only.
|
|
82
|
+
* Storage-layer document_id preserved as _vibe_doc_id for update/delete paths.
|
|
83
|
+
* See PayEz-Core/docs/vibe-primary-key-standard.md
|
|
82
84
|
*
|
|
83
85
|
* @example
|
|
84
|
-
* const raw = { document_id: 123, data: '{"name":"John","email":"john@example.com"}' };
|
|
86
|
+
* const raw = { document_id: 123, data: '{"user_id":15,"name":"John","email":"john@example.com"}' };
|
|
85
87
|
* const unwrapped = unwrapVibeDocument(raw);
|
|
86
|
-
* // => {
|
|
88
|
+
* // => { user_id: 15, name: 'John', email: 'john@example.com', _vibe_doc_id: 123 }
|
|
87
89
|
*/
|
|
88
90
|
function unwrapVibeDocument(doc) {
|
|
89
91
|
if (!doc)
|
|
90
92
|
return null;
|
|
91
|
-
// Handle case where doc is already unwrapped (has
|
|
92
|
-
if ('
|
|
93
|
+
// Handle case where doc is already unwrapped (has schema fields directly)
|
|
94
|
+
if (!('document_id' in doc) && !('data' in doc)) {
|
|
93
95
|
return doc;
|
|
94
96
|
}
|
|
95
97
|
const wrapper = doc;
|
|
@@ -106,12 +108,12 @@ function unwrapVibeDocument(doc) {
|
|
|
106
108
|
else if (typeof wrapper.data === 'object' && wrapper.data !== null) {
|
|
107
109
|
parsedData = wrapper.data;
|
|
108
110
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
// Preserve document_id as _vibe_doc_id for Vibe API update/delete paths only
|
|
112
|
+
const documentId = wrapper.document_id ?? doc.document_id;
|
|
113
|
+
if (documentId != null) {
|
|
114
|
+
parsedData._vibe_doc_id = documentId;
|
|
115
|
+
}
|
|
116
|
+
return parsedData;
|
|
115
117
|
}
|
|
116
118
|
/**
|
|
117
119
|
* Extract and unwrap array of documents from Vibe response.
|
package/package.json
CHANGED
package/src/vibe/generic.ts
CHANGED
|
@@ -98,21 +98,23 @@ export interface VibeDocumentWrapper {
|
|
|
98
98
|
* Vibe returns documents with a wrapper where actual data is a JSON string.
|
|
99
99
|
*
|
|
100
100
|
* @param doc - Raw Vibe document (wrapper format)
|
|
101
|
-
* @returns Unwrapped document with
|
|
101
|
+
* @returns Unwrapped document with schema fields only.
|
|
102
|
+
* Storage-layer document_id preserved as _vibe_doc_id for update/delete paths.
|
|
103
|
+
* See PayEz-Core/docs/vibe-primary-key-standard.md
|
|
102
104
|
*
|
|
103
105
|
* @example
|
|
104
|
-
* const raw = { document_id: 123, data: '{"name":"John","email":"john@example.com"}' };
|
|
106
|
+
* const raw = { document_id: 123, data: '{"user_id":15,"name":"John","email":"john@example.com"}' };
|
|
105
107
|
* const unwrapped = unwrapVibeDocument(raw);
|
|
106
|
-
* // => {
|
|
108
|
+
* // => { user_id: 15, name: 'John', email: 'john@example.com', _vibe_doc_id: 123 }
|
|
107
109
|
*/
|
|
108
110
|
export function unwrapVibeDocument<T extends Record<string, unknown> = Record<string, unknown>>(
|
|
109
111
|
doc: VibeDocumentWrapper | Record<string, unknown> | null | undefined
|
|
110
|
-
): (T & {
|
|
112
|
+
): (T & { _vibe_doc_id?: number }) | null {
|
|
111
113
|
if (!doc) return null;
|
|
112
114
|
|
|
113
|
-
// Handle case where doc is already unwrapped (has
|
|
114
|
-
if ('
|
|
115
|
-
return doc as T & {
|
|
115
|
+
// Handle case where doc is already unwrapped (has schema fields directly)
|
|
116
|
+
if (!('document_id' in doc) && !('data' in doc)) {
|
|
117
|
+
return doc as T & { _vibe_doc_id?: number };
|
|
116
118
|
}
|
|
117
119
|
|
|
118
120
|
const wrapper = doc as VibeDocumentWrapper;
|
|
@@ -129,13 +131,13 @@ export function unwrapVibeDocument<T extends Record<string, unknown> = Record<st
|
|
|
129
131
|
parsedData = wrapper.data;
|
|
130
132
|
}
|
|
131
133
|
|
|
132
|
-
|
|
134
|
+
// Preserve document_id as _vibe_doc_id for Vibe API update/delete paths only
|
|
135
|
+
const documentId = wrapper.document_id ?? (doc as any).document_id;
|
|
136
|
+
if (documentId != null) {
|
|
137
|
+
parsedData._vibe_doc_id = documentId;
|
|
138
|
+
}
|
|
133
139
|
|
|
134
|
-
return {
|
|
135
|
-
id: documentId,
|
|
136
|
-
document_id: documentId,
|
|
137
|
-
...parsedData,
|
|
138
|
-
} as T & { id: number; document_id: number };
|
|
140
|
+
return parsedData as T & { _vibe_doc_id?: number };
|
|
139
141
|
}
|
|
140
142
|
|
|
141
143
|
/**
|
|
@@ -151,7 +153,7 @@ export function unwrapVibeDocument<T extends Record<string, unknown> = Record<st
|
|
|
151
153
|
*/
|
|
152
154
|
export function extractVibeDocuments<T extends Record<string, unknown> = Record<string, unknown>>(
|
|
153
155
|
responseData: unknown
|
|
154
|
-
): Array<T & {
|
|
156
|
+
): Array<T & { _vibe_doc_id?: number }> {
|
|
155
157
|
if (!responseData || typeof responseData !== 'object') {
|
|
156
158
|
return [];
|
|
157
159
|
}
|
|
@@ -171,7 +173,7 @@ export function extractVibeDocuments<T extends Record<string, unknown> = Record<
|
|
|
171
173
|
|
|
172
174
|
return docs
|
|
173
175
|
.map((doc) => unwrapVibeDocument<T>(doc))
|
|
174
|
-
.filter((d): d is T & {
|
|
176
|
+
.filter((d): d is T & { _vibe_doc_id?: number } => d !== null);
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
// -----------------------------------------------------------------------------
|
|
@@ -196,7 +198,7 @@ export class GenericTableDelegate<T extends Record<string, unknown> = Record<str
|
|
|
196
198
|
/**
|
|
197
199
|
* Find multiple records with optional filtering and pagination.
|
|
198
200
|
*/
|
|
199
|
-
async findMany(options?: FindManyOptions<T>): Promise<FindManyResult<T & {
|
|
201
|
+
async findMany(options?: FindManyOptions<T>): Promise<FindManyResult<T & { _vibe_doc_id?: number }>> {
|
|
200
202
|
const params = new URLSearchParams();
|
|
201
203
|
|
|
202
204
|
// Build filter params
|
|
@@ -257,7 +259,7 @@ export class GenericTableDelegate<T extends Record<string, unknown> = Record<str
|
|
|
257
259
|
* Find a single record by ID.
|
|
258
260
|
* Throws VibeNotFoundError if not found.
|
|
259
261
|
*/
|
|
260
|
-
async findUnique(options: { where: { id: number } }): Promise<T & {
|
|
262
|
+
async findUnique(options: { where: { id: number } }): Promise<T & { _vibe_doc_id?: number }> {
|
|
261
263
|
const path = vibeTablePath(this.collection, this.tableName, options.where.id);
|
|
262
264
|
const url = `${this.client.getBaseUrl()}${path}`;
|
|
263
265
|
const response = await this.client.request<VibeDocumentWrapper>(url, 'GET');
|
|
@@ -275,7 +277,7 @@ export class GenericTableDelegate<T extends Record<string, unknown> = Record<str
|
|
|
275
277
|
/**
|
|
276
278
|
* Find a single record by ID, returns null if not found.
|
|
277
279
|
*/
|
|
278
|
-
async findUniqueOrNull(options: { where: { id: number } }): Promise<(T & {
|
|
280
|
+
async findUniqueOrNull(options: { where: { id: number } }): Promise<(T & { _vibe_doc_id?: number }) | null> {
|
|
279
281
|
try {
|
|
280
282
|
return await this.findUnique(options);
|
|
281
283
|
} catch (error) {
|
|
@@ -289,7 +291,7 @@ export class GenericTableDelegate<T extends Record<string, unknown> = Record<str
|
|
|
289
291
|
/**
|
|
290
292
|
* Find the first record matching the filter.
|
|
291
293
|
*/
|
|
292
|
-
async findFirst(options?: FindManyOptions<T>): Promise<(T & {
|
|
294
|
+
async findFirst(options?: FindManyOptions<T>): Promise<(T & { _vibe_doc_id?: number }) | null> {
|
|
293
295
|
const result = await this.findMany({ ...options, take: 1 });
|
|
294
296
|
return result.data[0] || null;
|
|
295
297
|
}
|
|
@@ -297,7 +299,7 @@ export class GenericTableDelegate<T extends Record<string, unknown> = Record<str
|
|
|
297
299
|
/**
|
|
298
300
|
* Create a new record.
|
|
299
301
|
*/
|
|
300
|
-
async create(options: { data: Partial<T> }): Promise<T & {
|
|
302
|
+
async create(options: { data: Partial<T> }): Promise<T & { _vibe_doc_id?: number }> {
|
|
301
303
|
const path = vibeTablePath(this.collection, this.tableName);
|
|
302
304
|
const url = `${this.client.getBaseUrl()}${path}`;
|
|
303
305
|
const response = await this.client.request<VibeDocumentWrapper>(url, 'POST', options.data);
|
|
@@ -311,7 +313,7 @@ export class GenericTableDelegate<T extends Record<string, unknown> = Record<str
|
|
|
311
313
|
/**
|
|
312
314
|
* Update an existing record by ID.
|
|
313
315
|
*/
|
|
314
|
-
async update(options: { where: { id: number }; data: Partial<T> }): Promise<T & {
|
|
316
|
+
async update(options: { where: { id: number }; data: Partial<T> }): Promise<T & { _vibe_doc_id?: number }> {
|
|
315
317
|
const path = vibeTablePath(this.collection, this.tableName, options.where.id);
|
|
316
318
|
const url = `${this.client.getBaseUrl()}${path}`;
|
|
317
319
|
const response = await this.client.request<VibeDocumentWrapper>(url, 'PUT', options.data);
|
|
@@ -325,7 +327,7 @@ export class GenericTableDelegate<T extends Record<string, unknown> = Record<str
|
|
|
325
327
|
/**
|
|
326
328
|
* Delete a record by ID (soft delete).
|
|
327
329
|
*/
|
|
328
|
-
async delete(options: { where: { id: number } }): Promise<T & {
|
|
330
|
+
async delete(options: { where: { id: number } }): Promise<T & { _vibe_doc_id?: number }> {
|
|
329
331
|
const path = vibeTablePath(this.collection, this.tableName, options.where.id);
|
|
330
332
|
const url = `${this.client.getBaseUrl()}${path}`;
|
|
331
333
|
const response = await this.client.request<VibeDocumentWrapper>(url, 'DELETE');
|