Skip to content
Open
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
2 changes: 2 additions & 0 deletions sdk/functions-schema/dist/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare const API_NAMES: readonly ["compute"];
export type ApiName = (typeof API_NAMES)[number];
4 changes: 4 additions & 0 deletions sdk/functions-schema/dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.API_NAMES = void 0;
exports.API_NAMES = ["compute"];
5 changes: 5 additions & 0 deletions sdk/functions-sdk/dist/compute/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* GraphQL SDK - auto-generated, do not edit
* @generated by @constructive-io/graphql-codegen
*/
export * from './orm';
21 changes: 21 additions & 0 deletions sdk/functions-sdk/dist/compute/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
/**
* GraphQL SDK - auto-generated, do not edit
* @generated by @constructive-io/graphql-codegen
*/
__exportStar(require("./orm"), exports);
97 changes: 97 additions & 0 deletions sdk/functions-sdk/dist/compute/orm/client.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* ORM Client - Runtime GraphQL executor
* @generated by @constructive-io/graphql-codegen
* DO NOT EDIT - changes will be overwritten
*/
import type { GraphQLAdapter, GraphQLError, QueryResult } from '@constructive-io/graphql-query/runtime';
import type { ConnectionState, ConnectionStateListener, RealtimeConfig, SubscriptionEvent, SubscriptionFieldMeta, Unsubscribe } from './realtime';
export type { GraphQLAdapter, GraphQLError, QueryResult, } from '@constructive-io/graphql-query/runtime';
export type { ConnectionState, ConnectionStateListener, RealtimeConfig, SubscribeOptions, SubscriptionEvent, SubscriptionFieldMeta, SubscriptionOperation, Unsubscribe, WsClient, } from './realtime';
export { RealtimeManager } from './realtime';
/**
* Default adapter that uses fetch for HTTP requests.
*
* When no custom fetch is provided, uses @constructive-io/fetch which
* handles *.localhost DNS rewriting and Host header preservation in
* Node.js. Pass a custom fetch to override for test mocking or custom
* proxy/credentials.
*/
export declare class FetchAdapter implements GraphQLAdapter {
private endpoint;
private headers;
private fetchFn;
constructor(endpoint: string, headers?: Record<string, string>, fetchFn?: typeof globalThis.fetch);
execute<T>(document: string, variables?: Record<string, unknown>): Promise<QueryResult<T>>;
setHeaders(headers: Record<string, string>): void;
getEndpoint(): string;
}
/**
* Configuration for creating an ORM client.
* Either provide endpoint (and optional headers/fetch) for HTTP requests,
* or provide a custom adapter for alternative execution strategies.
*/
export interface OrmClientConfig {
/** GraphQL endpoint URL (required if adapter not provided) */
endpoint?: string;
/** Default headers for HTTP requests (only used with endpoint) */
headers?: Record<string, string>;
/**
* Custom fetch implementation. Defaults to createFetch() from
* @constructive-io/graphql-query/runtime which handles *.localhost
* DNS and Host headers in Node.js. Pass your own for test mocking
* or custom proxy/credentials.
*/
fetch?: typeof globalThis.fetch;
/** Custom adapter for GraphQL execution (overrides endpoint/headers/fetch) */
adapter?: GraphQLAdapter;
/**
* Optional realtime (WebSocket) configuration.
* When provided, enables subscription methods on models.
* The WebSocket connection is created lazily on first subscribe().
*/
realtime?: RealtimeConfig;
}
/**
* Error thrown when GraphQL request fails
*/
export declare class GraphQLRequestError extends Error {
readonly errors: GraphQLError[];
readonly data: unknown;
constructor(errors: GraphQLError[], data?: unknown);
}
export declare class OrmClient {
private adapter;
private realtimeManager?;
constructor(config: OrmClientConfig);
execute<T>(document: string, variables?: Record<string, unknown>): Promise<QueryResult<T>>;
/**
* Subscribe to a GraphQL subscription operation.
* Used by generated model subscribe() methods.
* @throws Error if realtime is not configured
*/
subscribe<T>(meta: SubscriptionFieldMeta, document: string, variables: Record<string, unknown>, options: {
onEvent: (event: SubscriptionEvent<T>) => void;
onError?: (error: Error) => void;
onComplete?: () => void;
}): Unsubscribe;
/**
* Set headers for requests.
* Only works if the adapter supports headers.
*/
setHeaders(headers: Record<string, string>): void;
/**
* Get the endpoint URL.
* Returns empty string if the adapter doesn't have an endpoint.
*/
getEndpoint(): string;
/** Get current WebSocket connection state */
getConnectionState(): ConnectionState;
/** Register a listener for WebSocket connection state changes */
onConnectionStateChange(listener: ConnectionStateListener): Unsubscribe;
/** Number of active subscriptions */
getActiveSubscriptionCount(): number;
/** Whether realtime is configured */
get isRealtimeEnabled(): boolean;
/** Dispose the realtime manager (close WebSocket) */
dispose(): void;
}
152 changes: 152 additions & 0 deletions sdk/functions-sdk/dist/compute/orm/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.OrmClient = exports.GraphQLRequestError = exports.FetchAdapter = exports.RealtimeManager = void 0;
const runtime_1 = require("@constructive-io/graphql-query/runtime");
const realtime_1 = require("./realtime");
var realtime_2 = require("./realtime");
Object.defineProperty(exports, "RealtimeManager", { enumerable: true, get: function () { return realtime_2.RealtimeManager; } });
/**
* Default adapter that uses fetch for HTTP requests.
*
* When no custom fetch is provided, uses @constructive-io/fetch which
* handles *.localhost DNS rewriting and Host header preservation in
* Node.js. Pass a custom fetch to override for test mocking or custom
* proxy/credentials.
*/
class FetchAdapter {
endpoint;
headers;
fetchFn;
constructor(endpoint, headers, fetchFn) {
this.endpoint = endpoint;
this.headers = headers ?? {};
this.fetchFn = (fetchFn ?? (0, runtime_1.createFetch)()).bind(globalThis);
}
async execute(document, variables) {
const response = await this.fetchFn(this.endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
...this.headers,
},
body: JSON.stringify({
query: document,
variables: variables ?? {},
}),
});
if (!response.ok) {
return {
ok: false,
data: null,
errors: [{ message: `HTTP ${response.status}: ${response.statusText}` }],
};
}
const json = (await response.json());
if (json.errors && json.errors.length > 0) {
return {
ok: false,
data: null,
errors: json.errors,
};
}
return {
ok: true,
data: json.data,
errors: undefined,
};
}
setHeaders(headers) {
this.headers = { ...this.headers, ...headers };
}
getEndpoint() {
return this.endpoint;
}
}
exports.FetchAdapter = FetchAdapter;
/**
* Error thrown when GraphQL request fails
*/
class GraphQLRequestError extends Error {
errors;
data;
constructor(errors, data = null) {
const messages = errors.map((e) => e.message).join('; ');
super(`GraphQL Error: ${messages}`);
this.errors = errors;
this.data = data;
this.name = 'GraphQLRequestError';
}
}
exports.GraphQLRequestError = GraphQLRequestError;
class OrmClient {
adapter;
realtimeManager;
constructor(config) {
if (config.adapter) {
this.adapter = config.adapter;
}
else if (config.endpoint) {
this.adapter = new FetchAdapter(config.endpoint, config.headers, config.fetch);
}
else {
throw new Error('OrmClientConfig requires either an endpoint or a custom adapter');
}
if (config.realtime) {
this.realtimeManager = new realtime_1.RealtimeManager(config.realtime);
}
}
async execute(document, variables) {
return this.adapter.execute(document, variables);
}
/**
* Subscribe to a GraphQL subscription operation.
* Used by generated model subscribe() methods.
* @throws Error if realtime is not configured
*/
subscribe(meta, document, variables, options) {
if (!this.realtimeManager) {
throw new Error('Realtime not configured. Pass a `realtime` option to createClient() to enable subscriptions.');
}
return this.realtimeManager.subscribe(meta, document, variables, options);
}
/**
* Set headers for requests.
* Only works if the adapter supports headers.
*/
setHeaders(headers) {
if (this.adapter.setHeaders) {
this.adapter.setHeaders(headers);
}
}
/**
* Get the endpoint URL.
* Returns empty string if the adapter doesn't have an endpoint.
*/
getEndpoint() {
return this.adapter.getEndpoint?.() ?? '';
}
/** Get current WebSocket connection state */
getConnectionState() {
return this.realtimeManager?.getConnectionState() ?? 'disconnected';
}
/** Register a listener for WebSocket connection state changes */
onConnectionStateChange(listener) {
if (!this.realtimeManager)
return () => { };
return this.realtimeManager.onConnectionStateChange(listener);
}
/** Number of active subscriptions */
getActiveSubscriptionCount() {
return this.realtimeManager?.getActiveSubscriptionCount() ?? 0;
}
/** Whether realtime is configured */
get isRealtimeEnabled() {
return this.realtimeManager !== undefined;
}
/** Dispose the realtime manager (close WebSocket) */
dispose() {
this.realtimeManager?.dispose();
}
}
exports.OrmClient = OrmClient;
51 changes: 51 additions & 0 deletions sdk/functions-sdk/dist/compute/orm/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { OrmClientConfig } from './client';
import { PlatformSecretDefinitionModel } from './models/platformSecretDefinition';
import { PlatformFunctionExecutionLogModel } from './models/platformFunctionExecutionLog';
import { PlatformNamespaceModel } from './models/platformNamespace';
import { PlatformFunctionInvocationModel } from './models/platformFunctionInvocation';
import { PlatformNamespaceEventModel } from './models/platformNamespaceEvent';
import { PlatformFunctionDefinitionModel } from './models/platformFunctionDefinition';
export type { OrmClientConfig, QueryResult, GraphQLError, GraphQLAdapter } from './client';
export { GraphQLRequestError, FetchAdapter } from './client';
export { QueryBuilder } from './query-builder';
export * from './select-types';
export * from './models';
export { createMutationOperations } from './mutation';
/**
* Create an ORM client instance
*
* @example
* ```typescript
* const db = createClient({
* endpoint: 'https://api.example.com/graphql',
* headers: { Authorization: 'Bearer token' },
* });
*
* // Query users
* const users = await db.user.findMany({
* select: { id: true, name: true },
* first: 10,
* }).execute();
*
* // Create a user
* const newUser = await db.user.create({
* data: { name: 'John', email: 'john@example.com' },
* select: { id: true },
* }).execute();
* ```
*/
export declare function createClient(config: OrmClientConfig): {
platformSecretDefinition: PlatformSecretDefinitionModel;
platformFunctionExecutionLog: PlatformFunctionExecutionLogModel;
platformNamespace: PlatformNamespaceModel;
platformFunctionInvocation: PlatformFunctionInvocationModel;
platformNamespaceEvent: PlatformNamespaceEventModel;
platformFunctionDefinition: PlatformFunctionDefinitionModel;
mutation: {
provisionBucket: <S extends import("./input-types").ProvisionBucketPayloadSelect>(args: import("./mutation").ProvisionBucketVariables, options: {
select: S;
} & import("./select-types").StrictSelect<S, import("./input-types").ProvisionBucketPayloadSelect>) => import("./query-builder").QueryBuilder<{
provisionBucket: import("./select-types").InferSelectResult<import("./input-types").ProvisionBucketPayload, S> | null;
}>;
};
};
Loading
Loading