@edge-base/core 0.1.1
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/context.d.ts +36 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +60 -0
- package/dist/context.js.map +1 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +26 -0
- package/dist/errors.js.map +1 -0
- package/dist/field-ops.d.ts +43 -0
- package/dist/field-ops.d.ts.map +1 -0
- package/dist/field-ops.js +61 -0
- package/dist/field-ops.js.map +1 -0
- package/dist/functions.d.ts +50 -0
- package/dist/functions.d.ts.map +1 -0
- package/dist/functions.js +56 -0
- package/dist/functions.js.map +1 -0
- package/dist/generated/api-core.d.ts +503 -0
- package/dist/generated/api-core.d.ts.map +1 -0
- package/dist/generated/api-core.js +496 -0
- package/dist/generated/api-core.js.map +1 -0
- package/dist/generated/client-wrappers.d.ts +120 -0
- package/dist/generated/client-wrappers.d.ts.map +1 -0
- package/dist/generated/client-wrappers.js +219 -0
- package/dist/generated/client-wrappers.js.map +1 -0
- package/dist/http.d.ts +57 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +198 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/mime.d.ts +15 -0
- package/dist/mime.d.ts.map +1 -0
- package/dist/mime.js +84 -0
- package/dist/mime.js.map +1 -0
- package/dist/storage.d.ts +246 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +460 -0
- package/dist/storage.js.map +1 -0
- package/dist/table.d.ts +322 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +734 -0
- package/dist/table.js.map +1 -0
- package/dist/transport-adapter.d.ts +37 -0
- package/dist/transport-adapter.d.ts.map +1 -0
- package/dist/transport-adapter.js +70 -0
- package/dist/transport-adapter.js.map +1 -0
- package/dist/types.d.ts +39 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +49 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context management for legacy isolateBy compatibility state.
|
|
3
|
+
* HTTP DB routing now uses explicit `db(namespace, instanceId)` paths.
|
|
4
|
+
*/
|
|
5
|
+
export type ContextValue = Record<string, string>;
|
|
6
|
+
/** Internal event type for context changes */
|
|
7
|
+
export type ContextChangeHandler = (ctx: ContextValue) => void;
|
|
8
|
+
export declare class ContextManager {
|
|
9
|
+
private context;
|
|
10
|
+
private listeners;
|
|
11
|
+
/**
|
|
12
|
+
* Set isolateBy context keys.
|
|
13
|
+
* Retained for SDK compatibility; current HTTP clients do not serialize this
|
|
14
|
+
* state into request headers.
|
|
15
|
+
*
|
|
16
|
+
* NOTE: 'auth.id' key is silently ignored (server extracts from JWT).
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* client.setContext({ workspaceId: 'ws-123' });
|
|
20
|
+
*/
|
|
21
|
+
setContext(ctx: ContextValue): void;
|
|
22
|
+
/**
|
|
23
|
+
* Get the current context value
|
|
24
|
+
*/
|
|
25
|
+
getContext(): ContextValue;
|
|
26
|
+
/**
|
|
27
|
+
* Validate that a required isolateBy key is present in context.
|
|
28
|
+
* Throws EdgeBaseError if missing (pre-server-call defense,).
|
|
29
|
+
*/
|
|
30
|
+
requireContextKey(key: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Subscribe to context changes (internal use for Database Live reconnect in M6)
|
|
33
|
+
*/
|
|
34
|
+
onContextChange(handler: ContextChangeHandler): () => void;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAElD,8CAA8C;AAC9C,MAAM,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,YAAY,KAAK,IAAI,CAAC;AAE/D,qBAAa,cAAc;IACzB,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,SAAS,CAA8B;IAE/C;;;;;;;;;OASG;IACH,UAAU,CAAC,GAAG,EAAE,YAAY,GAAG,IAAI;IAenC;;OAEG;IACH,UAAU,IAAI,YAAY;IAI1B;;;OAGG;IACH,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAUpC;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,IAAI;CAM3D"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context management for legacy isolateBy compatibility state.
|
|
3
|
+
* HTTP DB routing now uses explicit `db(namespace, instanceId)` paths.
|
|
4
|
+
*/
|
|
5
|
+
import { EdgeBaseError } from './errors.js';
|
|
6
|
+
export class ContextManager {
|
|
7
|
+
context = {};
|
|
8
|
+
listeners = [];
|
|
9
|
+
/**
|
|
10
|
+
* Set isolateBy context keys.
|
|
11
|
+
* Retained for SDK compatibility; current HTTP clients do not serialize this
|
|
12
|
+
* state into request headers.
|
|
13
|
+
*
|
|
14
|
+
* NOTE: 'auth.id' key is silently ignored (server extracts from JWT).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* client.setContext({ workspaceId: 'ws-123' });
|
|
18
|
+
*/
|
|
19
|
+
setContext(ctx) {
|
|
20
|
+
// Filter out auth.id — server extracts from JWT only
|
|
21
|
+
const filtered = {};
|
|
22
|
+
for (const [key, value] of Object.entries(ctx)) {
|
|
23
|
+
if (key === 'auth.id')
|
|
24
|
+
continue;
|
|
25
|
+
filtered[key] = value;
|
|
26
|
+
}
|
|
27
|
+
this.context = filtered;
|
|
28
|
+
// Emit contextChange event (M5: internal event only; M6: Database Live reconnect)
|
|
29
|
+
for (const listener of this.listeners) {
|
|
30
|
+
listener(this.context);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get the current context value
|
|
35
|
+
*/
|
|
36
|
+
getContext() {
|
|
37
|
+
return { ...this.context };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Validate that a required isolateBy key is present in context.
|
|
41
|
+
* Throws EdgeBaseError if missing (pre-server-call defense,).
|
|
42
|
+
*/
|
|
43
|
+
requireContextKey(key) {
|
|
44
|
+
if (key === 'auth.id')
|
|
45
|
+
return; // auth.id is handled via JWT, not context
|
|
46
|
+
if (!(key in this.context)) {
|
|
47
|
+
throw new EdgeBaseError(400, `Missing context key "${key}". Provide it when calling db(namespace, id).`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Subscribe to context changes (internal use for Database Live reconnect in M6)
|
|
52
|
+
*/
|
|
53
|
+
onContextChange(handler) {
|
|
54
|
+
this.listeners.push(handler);
|
|
55
|
+
return () => {
|
|
56
|
+
this.listeners = this.listeners.filter((h) => h !== handler);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAO5C,MAAM,OAAO,cAAc;IACjB,OAAO,GAAiB,EAAE,CAAC;IAC3B,SAAS,GAA2B,EAAE,CAAC;IAE/C;;;;;;;;;OASG;IACH,UAAU,CAAC,GAAiB;QAC1B,qDAAqD;QACrD,MAAM,QAAQ,GAAiB,EAAE,CAAC;QAClC,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/C,IAAI,GAAG,KAAK,SAAS;gBAAE,SAAS;YAChC,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxB,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC;QAExB,kFAAkF;QAClF,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACtC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAED;;OAEG;IACH,UAAU;QACR,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;IAED;;;OAGG;IACH,iBAAiB,CAAC,GAAW;QAC3B,IAAI,GAAG,KAAK,SAAS;YAAE,OAAO,CAAC,0CAA0C;QACzE,IAAI,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YAC3B,MAAM,IAAI,aAAa,CACrB,GAAG,EACH,wBAAwB,GAAG,+CAA+C,CAC3E,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACH,eAAe,CAAC,OAA6B;QAC3C,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7B,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC;QAC/D,CAAC,CAAC;IACJ,CAAC;CACF"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Error classes
|
|
3
|
+
* Extends @edge-base/shared EdgeBaseError with SDK-specific error types
|
|
4
|
+
*/
|
|
5
|
+
import { EdgeBaseError } from '@edge-base/shared';
|
|
6
|
+
export { EdgeBaseError };
|
|
7
|
+
export type { ErrorResponse, FieldError } from '@edge-base/shared';
|
|
8
|
+
/**
|
|
9
|
+
* Parse a server error response into a EdgeBaseError
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseErrorResponse(status: number, body: unknown): EdgeBaseError;
|
|
12
|
+
/**
|
|
13
|
+
* Create a network-level error (fetch failures, timeouts, etc.)
|
|
14
|
+
*/
|
|
15
|
+
export declare function networkError(message: string): EdgeBaseError;
|
|
16
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,CAAC;AACzB,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEnE;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,aAAa,CAgB/E;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CAE3D"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Error classes
|
|
3
|
+
* Extends @edge-base/shared EdgeBaseError with SDK-specific error types
|
|
4
|
+
*/
|
|
5
|
+
import { EdgeBaseError } from '@edge-base/shared';
|
|
6
|
+
export { EdgeBaseError };
|
|
7
|
+
/**
|
|
8
|
+
* Parse a server error response into a EdgeBaseError
|
|
9
|
+
*/
|
|
10
|
+
export function parseErrorResponse(status, body) {
|
|
11
|
+
if (body &&
|
|
12
|
+
typeof body === 'object' &&
|
|
13
|
+
'message' in body &&
|
|
14
|
+
typeof body.message === 'string') {
|
|
15
|
+
const err = body;
|
|
16
|
+
return new EdgeBaseError(status, err.message, err.data, typeof err.slug === 'string' ? err.slug : undefined);
|
|
17
|
+
}
|
|
18
|
+
return new EdgeBaseError(status, `Request failed with status ${status}`);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a network-level error (fetch failures, timeouts, etc.)
|
|
22
|
+
*/
|
|
23
|
+
export function networkError(message) {
|
|
24
|
+
return new EdgeBaseError(0, message);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,CAAC;AAGzB;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAAc,EAAE,IAAa;IAC9D,IACE,IAAI;QACJ,OAAO,IAAI,KAAK,QAAQ;QACxB,SAAS,IAAI,IAAI;QACjB,OAAQ,IAAgC,CAAC,OAAO,KAAK,QAAQ,EAC7D,CAAC;QACD,MAAM,GAAG,GAAG,IAA+B,CAAC;QAC5C,OAAO,IAAI,aAAa,CACtB,MAAM,EACN,GAAG,CAAC,OAAiB,EACrB,GAAG,CAAC,IAAqE,EACzE,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CACpD,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,aAAa,CAAC,MAAM,EAAE,8BAA8B,MAAM,EAAE,CAAC,CAAC;AAC3E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,OAAO,IAAI,aAAa,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field operation helpers for atomic update operations
|
|
3
|
+
*: increment, deleteField
|
|
4
|
+
*/
|
|
5
|
+
/** Internal sentinel symbol for field operations */
|
|
6
|
+
declare const FIELD_OP_SYMBOL: unique symbol;
|
|
7
|
+
export interface FieldOp {
|
|
8
|
+
readonly [FIELD_OP_SYMBOL]: true;
|
|
9
|
+
readonly $op: string;
|
|
10
|
+
readonly value?: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Atomic increment/decrement a numeric field.
|
|
14
|
+
* Server converts to: `field = field + n`
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* await client.db('shared').table('posts').doc('post-1').update({
|
|
18
|
+
* viewCount: increment(1), // viewCount = viewCount + 1
|
|
19
|
+
* likes: increment(-1), // likes = likes - 1
|
|
20
|
+
* });
|
|
21
|
+
*/
|
|
22
|
+
export declare function increment(n: number): FieldOp;
|
|
23
|
+
/**
|
|
24
|
+
* Set a field to NULL (semantic deletion).
|
|
25
|
+
* Server converts to: `field = NULL`
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* await client.db('shared').table('posts').doc('post-1').update({
|
|
29
|
+
* temporaryFlag: deleteField(),
|
|
30
|
+
* });
|
|
31
|
+
*/
|
|
32
|
+
export declare function deleteField(): FieldOp;
|
|
33
|
+
/**
|
|
34
|
+
* Check if a value is a field operation object
|
|
35
|
+
*/
|
|
36
|
+
export declare function isFieldOp(value: unknown): value is FieldOp;
|
|
37
|
+
/**
|
|
38
|
+
* Serialize data containing field operations for transmission to server.
|
|
39
|
+
* Strips internal symbol, keeps $op format for server parsing.
|
|
40
|
+
*/
|
|
41
|
+
export declare function serializeFieldOps(data: Record<string, unknown>): Record<string, unknown>;
|
|
42
|
+
export {};
|
|
43
|
+
//# sourceMappingURL=field-ops.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-ops.d.ts","sourceRoot":"","sources":["../src/field-ops.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,oDAAoD;AACpD,QAAA,MAAM,eAAe,eAAkC,CAAC;AAExD,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,CAAC,eAAe,CAAC,EAAE,IAAI,CAAC;IACjC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAE5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,IAAI,OAAO,CAErC;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAM1D;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAcxF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Field operation helpers for atomic update operations
|
|
3
|
+
*: increment, deleteField
|
|
4
|
+
*/
|
|
5
|
+
/** Internal sentinel symbol for field operations */
|
|
6
|
+
const FIELD_OP_SYMBOL = Symbol.for('edgebase:field-op');
|
|
7
|
+
/**
|
|
8
|
+
* Atomic increment/decrement a numeric field.
|
|
9
|
+
* Server converts to: `field = field + n`
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* await client.db('shared').table('posts').doc('post-1').update({
|
|
13
|
+
* viewCount: increment(1), // viewCount = viewCount + 1
|
|
14
|
+
* likes: increment(-1), // likes = likes - 1
|
|
15
|
+
* });
|
|
16
|
+
*/
|
|
17
|
+
export function increment(n) {
|
|
18
|
+
return { [FIELD_OP_SYMBOL]: true, $op: 'increment', value: n };
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Set a field to NULL (semantic deletion).
|
|
22
|
+
* Server converts to: `field = NULL`
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* await client.db('shared').table('posts').doc('post-1').update({
|
|
26
|
+
* temporaryFlag: deleteField(),
|
|
27
|
+
* });
|
|
28
|
+
*/
|
|
29
|
+
export function deleteField() {
|
|
30
|
+
return { [FIELD_OP_SYMBOL]: true, $op: 'deleteField' };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if a value is a field operation object
|
|
34
|
+
*/
|
|
35
|
+
export function isFieldOp(value) {
|
|
36
|
+
return (value !== null &&
|
|
37
|
+
typeof value === 'object' &&
|
|
38
|
+
FIELD_OP_SYMBOL in value);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Serialize data containing field operations for transmission to server.
|
|
42
|
+
* Strips internal symbol, keeps $op format for server parsing.
|
|
43
|
+
*/
|
|
44
|
+
export function serializeFieldOps(data) {
|
|
45
|
+
const result = {};
|
|
46
|
+
for (const [key, value] of Object.entries(data)) {
|
|
47
|
+
if (isFieldOp(value)) {
|
|
48
|
+
if (value.$op === 'increment') {
|
|
49
|
+
result[key] = { $op: 'increment', value: value.value };
|
|
50
|
+
}
|
|
51
|
+
else if (value.$op === 'deleteField') {
|
|
52
|
+
result[key] = { $op: 'deleteField' };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
result[key] = value;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=field-ops.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-ops.js","sourceRoot":"","sources":["../src/field-ops.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,oDAAoD;AACpD,MAAM,eAAe,GAAG,MAAM,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;AAQxD;;;;;;;;;GASG;AACH,MAAM,UAAU,SAAS,CAAC,CAAS;IACjC,OAAO,EAAE,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AACjE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,EAAE,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO,CACL,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,eAAe,IAAK,KAAiC,CACtD,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAA6B;IAC7D,MAAM,MAAM,GAA4B,EAAE,CAAC;IAC3C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QAChD,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;YACrB,IAAI,KAAK,CAAC,GAAG,KAAK,WAAW,EAAE,CAAC;gBAC9B,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;YACzD,CAAC;iBAAM,IAAI,KAAK,CAAC,GAAG,KAAK,aAAa,EAAE,CAAC;gBACvC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC;YACvC,CAAC;QACH,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACtB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FunctionsClient — Call EdgeBase App Functions from client or admin SDK.
|
|
3
|
+
*
|
|
4
|
+
* Auth tokens are auto-injected via HttpClient. Errors are thrown as EdgeBaseError.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Via client SDK
|
|
8
|
+
* const { data } = await client.functions.post('users', { name: 'June' });
|
|
9
|
+
*
|
|
10
|
+
* // Via admin SDK
|
|
11
|
+
* const users = await admin.functions.get('users');
|
|
12
|
+
*
|
|
13
|
+
* // With dynamic route params
|
|
14
|
+
* const user = await client.functions.get('users/abc123/profile');
|
|
15
|
+
*/
|
|
16
|
+
import type { HttpClient } from './http.js';
|
|
17
|
+
export interface FunctionCallOptions {
|
|
18
|
+
/** HTTP method (defaults to 'POST'). */
|
|
19
|
+
method?: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
20
|
+
/** Request body (ignored for GET). */
|
|
21
|
+
body?: unknown;
|
|
22
|
+
/** Query string parameters (appended to URL). */
|
|
23
|
+
query?: Record<string, string>;
|
|
24
|
+
}
|
|
25
|
+
export declare class FunctionsClient {
|
|
26
|
+
private httpClient;
|
|
27
|
+
constructor(httpClient: HttpClient);
|
|
28
|
+
/**
|
|
29
|
+
* Call a function by route path.
|
|
30
|
+
*
|
|
31
|
+
* @param name Function route path (e.g., 'hello', 'users/abc123/profile')
|
|
32
|
+
* @param options HTTP method, body, and query options
|
|
33
|
+
* @returns The function's return value
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* await client.functions.call('send-email', { method: 'POST', body: { to: 'user@test.com' } });
|
|
37
|
+
*/
|
|
38
|
+
call<T = unknown>(name: string, options?: FunctionCallOptions): Promise<T>;
|
|
39
|
+
/** GET /api/functions/{path} */
|
|
40
|
+
get<T = unknown>(path: string, query?: Record<string, string>): Promise<T>;
|
|
41
|
+
/** POST /api/functions/{path} */
|
|
42
|
+
post<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
43
|
+
/** PUT /api/functions/{path} */
|
|
44
|
+
put<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
45
|
+
/** PATCH /api/functions/{path} */
|
|
46
|
+
patch<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
47
|
+
/** DELETE /api/functions/{path} */
|
|
48
|
+
delete<T = unknown>(path: string): Promise<T>;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=functions.d.ts.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CAAC,CAAC;IAIlE,mCAAmC;IAC7B,MAAM,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;CAGpD"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// ─── FunctionsClient ───
|
|
2
|
+
export class FunctionsClient {
|
|
3
|
+
httpClient;
|
|
4
|
+
constructor(httpClient) {
|
|
5
|
+
this.httpClient = httpClient;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Call a function by route path.
|
|
9
|
+
*
|
|
10
|
+
* @param name Function route path (e.g., 'hello', 'users/abc123/profile')
|
|
11
|
+
* @param options HTTP method, body, and query options
|
|
12
|
+
* @returns The function's return value
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* await client.functions.call('send-email', { method: 'POST', body: { to: 'user@test.com' } });
|
|
16
|
+
*/
|
|
17
|
+
async call(name, options) {
|
|
18
|
+
const method = options?.method ?? 'POST';
|
|
19
|
+
const path = `/api/functions/${name}`;
|
|
20
|
+
switch (method) {
|
|
21
|
+
case 'GET':
|
|
22
|
+
return this.httpClient.get(path, options?.query);
|
|
23
|
+
case 'POST':
|
|
24
|
+
return this.httpClient.post(path, options?.body);
|
|
25
|
+
case 'PUT':
|
|
26
|
+
return this.httpClient.put(path, options?.body);
|
|
27
|
+
case 'PATCH':
|
|
28
|
+
return this.httpClient.patch(path, options?.body);
|
|
29
|
+
case 'DELETE':
|
|
30
|
+
return this.httpClient.delete(path);
|
|
31
|
+
default:
|
|
32
|
+
return this.httpClient.post(path, options?.body);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** GET /api/functions/{path} */
|
|
36
|
+
async get(path, query) {
|
|
37
|
+
return this.call(path, { method: 'GET', query });
|
|
38
|
+
}
|
|
39
|
+
/** POST /api/functions/{path} */
|
|
40
|
+
async post(path, body) {
|
|
41
|
+
return this.call(path, { method: 'POST', body });
|
|
42
|
+
}
|
|
43
|
+
/** PUT /api/functions/{path} */
|
|
44
|
+
async put(path, body) {
|
|
45
|
+
return this.call(path, { method: 'PUT', body });
|
|
46
|
+
}
|
|
47
|
+
/** PATCH /api/functions/{path} */
|
|
48
|
+
async patch(path, body) {
|
|
49
|
+
return this.call(path, { method: 'PATCH', body });
|
|
50
|
+
}
|
|
51
|
+
/** DELETE /api/functions/{path} */
|
|
52
|
+
async delete(path) {
|
|
53
|
+
return this.call(path, { method: 'DELETE' });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=functions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.js","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AA4BA,0BAA0B;AAE1B,MAAM,OAAO,eAAe;IAClB,UAAU,CAAa;IAE/B,YAAY,UAAsB;QAChC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,IAAI,CAAc,IAAY,EAAE,OAA6B;QACjE,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,IAAI,MAAM,CAAC;QACzC,MAAM,IAAI,GAAG,kBAAkB,IAAI,EAAE,CAAC;QAEtC,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,KAAK;gBACR,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAI,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;YACtD,KAAK,MAAM;gBACT,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAI,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YACtD,KAAK,KAAK;gBACR,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAI,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YACrD,KAAK,OAAO;gBACV,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAI,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;YACvD,KAAK,Q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