@xylex-group/athena 1.7.0 → 2.0.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.cjs CHANGED
@@ -503,544 +503,1614 @@ function identifier(...segments) {
503
503
  return new SqlIdentifierPath(expandedSegments);
504
504
  }
505
505
 
506
- // src/client.ts
507
- var DEFAULT_COLUMNS = "*";
508
- var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
509
- var SAFE_CAST_PATTERN = /^[a-z_][a-z0-9_]*(?:\[\])?$/i;
510
- function formatResult(response) {
511
- const result = {
512
- data: response.data ?? null,
513
- error: response.error ?? null,
514
- errorDetails: response.errorDetails ?? null,
515
- status: response.status,
516
- raw: response.raw
517
- };
518
- if (response.count !== void 0) {
519
- result.count = response.count;
506
+ // src/auth/client.ts
507
+ var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
508
+ var FALLBACK_SDK_VERSION2 = "1.0.0";
509
+ var SDK_NAME2 = "xylex-group/athena-auth";
510
+ var SDK_VERSION2 = typeof process !== "undefined" && process?.env?.npm_package_version ? process.env.npm_package_version : FALLBACK_SDK_VERSION2;
511
+ var SDK_HEADER_VALUE2 = `${SDK_NAME2} ${SDK_VERSION2}`;
512
+ function normalizeBaseUrl(baseUrl) {
513
+ return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
514
+ }
515
+ function isRecord2(value) {
516
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
517
+ }
518
+ function normalizeHeaderValue2(value) {
519
+ return value ? value : void 0;
520
+ }
521
+ function parseResponseBody2(rawText, contentType) {
522
+ if (!rawText) {
523
+ return { parsed: null, parseFailed: false };
524
+ }
525
+ const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
526
+ const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
527
+ if (!looksJson) {
528
+ return { parsed: rawText, parseFailed: false };
529
+ }
530
+ try {
531
+ return { parsed: JSON.parse(rawText), parseFailed: false };
532
+ } catch {
533
+ return { parsed: rawText, parseFailed: true };
520
534
  }
521
- return result;
522
535
  }
523
- function toSingleResult(response) {
524
- const payload = response.data;
525
- const singleData = Array.isArray(payload) ? payload.length ? payload[0] : null : payload ?? null;
536
+ function resolveRequestId2(headers) {
537
+ return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
538
+ }
539
+ function resolveErrorMessage2(payload, fallback) {
540
+ if (isRecord2(payload)) {
541
+ const messageCandidates = [payload.error, payload.message, payload.details];
542
+ for (const candidate of messageCandidates) {
543
+ if (typeof candidate === "string" && candidate.trim().length > 0) {
544
+ return candidate.trim();
545
+ }
546
+ }
547
+ }
548
+ if (typeof payload === "string" && payload.trim().length > 0) {
549
+ return payload.trim();
550
+ }
551
+ return fallback;
552
+ }
553
+ function toErrorDetails(input) {
526
554
  return {
527
- ...response,
528
- data: singleData
555
+ code: input.code,
556
+ message: input.message,
557
+ status: input.status,
558
+ endpoint: input.endpoint,
559
+ method: input.method,
560
+ requestId: input.requestId,
561
+ hint: input.hint,
562
+ cause: input.cause
529
563
  };
530
564
  }
531
- function mergeOptions(...options) {
532
- return options.reduce((acc, next) => {
533
- if (!next) return acc;
534
- return { ...acc, ...next };
535
- }, void 0);
536
- }
537
- function createMutationQuery(executor, defaultColumns = DEFAULT_COLUMNS) {
538
- let selectedColumns = defaultColumns === null ? void 0 : defaultColumns;
539
- let selectedOptions;
540
- let promise = null;
541
- const run = (columns, options) => {
542
- const payloadColumns = columns ?? selectedColumns;
543
- const payloadOptions = options ?? selectedOptions;
544
- if (!promise) {
545
- promise = executor(payloadColumns, payloadOptions);
565
+ function mergeCallOptions(base, override) {
566
+ if (!base && !override) return void 0;
567
+ return {
568
+ ...base,
569
+ ...override,
570
+ headers: {
571
+ ...base?.headers ?? {},
572
+ ...override?.headers ?? {}
546
573
  }
547
- return promise;
548
574
  };
549
- const mutationQuery = {
550
- select(columns = selectedColumns, options) {
551
- selectedColumns = columns;
552
- selectedOptions = options ?? selectedOptions;
553
- return run(columns, options);
554
- },
555
- returning(columns = selectedColumns, options) {
556
- return mutationQuery.select(columns, options);
557
- },
558
- single(columns = selectedColumns, options) {
559
- selectedColumns = columns;
560
- selectedOptions = options ?? selectedOptions;
561
- return run(columns, options).then(toSingleResult);
562
- },
563
- maybeSingle(columns = selectedColumns, options) {
564
- return mutationQuery.single(columns, options);
565
- },
566
- then(onfulfilled, onrejected) {
567
- return run(selectedColumns, selectedOptions).then(onfulfilled, onrejected);
568
- },
569
- catch(onrejected) {
570
- return run(selectedColumns, selectedOptions).catch(onrejected);
571
- },
572
- finally(onfinally) {
573
- return run(selectedColumns, selectedOptions).finally(onfinally);
574
- }
575
+ }
576
+ function extractFetchOptions(input) {
577
+ if (!input) {
578
+ return {
579
+ payload: void 0,
580
+ fetchOptions: void 0
581
+ };
582
+ }
583
+ const { fetchOptions, ...rest } = input;
584
+ const hasPayloadKeys = Object.keys(rest).length > 0;
585
+ return {
586
+ payload: hasPayloadKeys ? rest : void 0,
587
+ fetchOptions
575
588
  };
576
- return mutationQuery;
577
589
  }
578
- function getResourceId(state) {
579
- const candidate = state.conditions.find(
580
- (condition) => condition.operator === "eq" && (condition.column === "resource_id" || condition.column === "id")
581
- );
582
- return candidate?.value?.toString();
590
+ function buildHeaders2(config, options) {
591
+ const headers = {
592
+ "Content-Type": "application/json",
593
+ "X-Athena-Sdk": SDK_HEADER_VALUE2
594
+ };
595
+ const apiKey = options?.apiKey ?? config.apiKey;
596
+ if (apiKey) {
597
+ headers.apikey = apiKey;
598
+ headers["x-api-key"] = apiKey;
599
+ }
600
+ const bearerToken = options?.bearerToken ?? config.bearerToken;
601
+ if (bearerToken) {
602
+ headers.Authorization = `Bearer ${bearerToken}`;
603
+ }
604
+ const mergedExtraHeaders = {
605
+ ...config.headers ?? {},
606
+ ...options?.headers ?? {}
607
+ };
608
+ Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
609
+ const normalized = normalizeHeaderValue2(value);
610
+ if (normalized) {
611
+ headers[key] = normalized;
612
+ }
613
+ });
614
+ return headers;
583
615
  }
584
- function stringifyFilterValue(value) {
616
+ function appendQueryParam(searchParams, key, value) {
617
+ if (value === void 0 || value === null) return;
585
618
  if (Array.isArray(value)) {
586
- return value.join(",");
619
+ value.forEach((item) => {
620
+ searchParams.append(key, String(item));
621
+ });
622
+ return;
587
623
  }
588
- return String(value);
589
- }
590
- function isUuidString(value) {
591
- return UUID_PATTERN.test(value.trim());
592
- }
593
- function isUuidIdentifierColumn(column) {
594
- return column === "id" || /(?:^|_)uuid(?:_|$)/i.test(column) || /_id$/i.test(column);
624
+ searchParams.append(key, String(value));
595
625
  }
596
- function shouldUseUuidTextComparison(column, value) {
597
- return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
626
+ function buildRequestUrl(baseUrl, endpoint, query) {
627
+ const url = `${baseUrl}${endpoint}`;
628
+ if (!query || Object.keys(query).length === 0) return url;
629
+ const searchParams = new URLSearchParams();
630
+ Object.entries(query).forEach(([key, value]) => appendQueryParam(searchParams, key, value));
631
+ const queryText = searchParams.toString();
632
+ return queryText ? `${url}?${queryText}` : url;
598
633
  }
599
- function normalizeCast(cast) {
600
- const normalized = cast.trim().toLowerCase();
601
- if (!SAFE_CAST_PATTERN.test(normalized)) {
602
- throw new Error(`Invalid cast type "${cast}"`);
634
+ function inferDefaultMethod(endpoint) {
635
+ if (endpoint.startsWith("/reset-password/")) {
636
+ return "GET";
603
637
  }
604
- return normalized;
605
- }
606
- function escapeSqlStringLiteral(value) {
607
- return value.replace(/'/g, "''");
608
- }
609
- function toSqlLiteral(value) {
610
- if (value === null) return "NULL";
611
- if (typeof value === "number") return Number.isFinite(value) ? String(value) : "NULL";
612
- if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
613
- return `'${escapeSqlStringLiteral(value)}'`;
614
- }
615
- function withCast(expression, cast) {
616
- if (!cast) return expression;
617
- return `${expression}::${normalizeCast(cast)}`;
618
- }
619
- function buildSelectColumnsClause(columns) {
620
- if (Array.isArray(columns)) {
621
- return columns.map((column) => quoteQualifiedIdentifier(column)).join(", ");
638
+ switch (endpoint) {
639
+ case "/get-session":
640
+ case "/list-sessions":
641
+ case "/verify-email":
642
+ case "/change-email/verify":
643
+ case "/delete-user/verify":
644
+ case "/email-list":
645
+ case "/email/list":
646
+ case "/delete-user/callback":
647
+ case "/list-accounts":
648
+ case "/passkey/generate-register-options":
649
+ case "/passkey/list-user-passkeys":
650
+ case "/.well-known/webauthn":
651
+ case "/admin/list-users":
652
+ case "/admin/athena-client/list":
653
+ case "/admin/audit-log/list":
654
+ case "/admin/email/get":
655
+ case "/admin/email-failure/list":
656
+ case "/admin/email-failure/get":
657
+ case "/admin/email-template/get":
658
+ case "/admin/email-template/list":
659
+ case "/admin/email/list":
660
+ case "/api-key/get":
661
+ case "/api-key/list":
662
+ case "/organization/get-full-organization":
663
+ case "/organization/list":
664
+ case "/organization/get-invitation":
665
+ case "/organization/list-invitations":
666
+ case "/organization/list-user-invitations":
667
+ case "/organization/list-members":
668
+ case "/organization/get-active-member":
669
+ case "/health":
670
+ case "/ok":
671
+ case "/error":
672
+ return "GET";
673
+ default:
674
+ return "POST";
622
675
  }
623
- return quoteSelectColumnsExpression(columns);
624
676
  }
625
- function conditionToSqlClause(condition) {
626
- if (!condition.column) return null;
627
- const column = withCast(quoteQualifiedIdentifier(condition.column), condition.column_cast);
628
- const value = condition.value;
629
- const sqlOperator = {
630
- eq: "=",
631
- neq: "!=",
632
- gt: ">",
633
- gte: ">=",
634
- lt: "<",
635
- lte: "<=",
636
- like: "LIKE",
637
- ilike: "ILIKE"
677
+ async function callAuthEndpoint(config, context, body, query, options) {
678
+ const baseUrl = normalizeBaseUrl(options?.baseUrl ?? config.baseUrl);
679
+ const url = buildRequestUrl(baseUrl, context.endpoint, query);
680
+ const headers = buildHeaders2(config, options);
681
+ const credentials = options?.credentials ?? config.credentials ?? "include";
682
+ const requestInit = {
683
+ method: context.method,
684
+ headers,
685
+ credentials,
686
+ signal: options?.signal
638
687
  };
639
- switch (condition.operator) {
640
- case "eq":
641
- case "neq":
642
- case "gt":
643
- case "gte":
644
- case "lt":
645
- case "lte":
646
- case "like":
647
- case "ilike": {
648
- if (Array.isArray(value) || value === void 0) return null;
649
- const rhs = withCast(toSqlLiteral(value), condition.value_cast);
650
- return `${column} ${sqlOperator[condition.operator]} ${rhs}`;
651
- }
652
- case "is": {
653
- if (value === null) return `${column} IS NULL`;
654
- if (value === true) return `${column} IS TRUE`;
655
- if (value === false) return `${column} IS FALSE`;
656
- return null;
657
- }
658
- case "in": {
659
- if (!Array.isArray(value)) return null;
660
- if (value.length === 0) return "FALSE";
661
- const values = value.map((item) => withCast(toSqlLiteral(item), condition.value_cast));
662
- return `${column} IN (${values.join(", ")})`;
663
- }
664
- default:
665
- return null;
666
- }
667
- }
668
- function buildTypedSelectQuery(input) {
669
- const whereClauses = [];
670
- for (const condition of input.conditions) {
671
- const clause = conditionToSqlClause(condition);
672
- if (!clause) return null;
673
- whereClauses.push(clause);
674
- }
675
- let limit = input.limit;
676
- let offset = input.offset;
677
- if (limit === void 0 && input.pageSize !== void 0) {
678
- limit = input.pageSize;
679
- }
680
- if (offset === void 0 && input.pageSize !== void 0 && input.currentPage !== void 0 && input.currentPage > 0) {
681
- offset = (input.currentPage - 1) * input.pageSize;
682
- }
683
- const sqlParts = [
684
- `SELECT ${buildSelectColumnsClause(input.columns)} FROM ${quoteQualifiedIdentifier(input.tableName)}`
685
- ];
686
- if (whereClauses.length > 0) {
687
- sqlParts.push(`WHERE ${whereClauses.join(" AND ")}`);
688
- }
689
- if (input.order?.field) {
690
- const direction = input.order.direction === "descending" ? "DESC" : "ASC";
691
- sqlParts.push(`ORDER BY ${quoteQualifiedIdentifier(input.order.field)} ${direction}`);
692
- }
693
- if (limit !== void 0) {
694
- sqlParts.push(`LIMIT ${Math.max(0, Math.trunc(limit))}`);
688
+ if (context.method !== "GET") {
689
+ requestInit.body = JSON.stringify(body ?? {});
695
690
  }
696
- if (offset !== void 0) {
697
- sqlParts.push(`OFFSET ${Math.max(0, Math.trunc(offset))}`);
691
+ const fetcher = config.fetch ?? globalThis.fetch;
692
+ if (!fetcher) {
693
+ const details = toErrorDetails({
694
+ code: "UNKNOWN_ERROR",
695
+ message: "No fetch implementation available for auth client",
696
+ status: 0,
697
+ endpoint: context.endpoint,
698
+ method: context.method,
699
+ hint: "Use Node 18+ or provide `fetch` via createClient(..., { auth: { fetch } }) or createAuthClient({ fetch })"
700
+ });
701
+ return {
702
+ ok: false,
703
+ status: 0,
704
+ data: null,
705
+ error: details.message,
706
+ errorDetails: details,
707
+ raw: null
708
+ };
698
709
  }
699
- return `${sqlParts.join(" ")};`;
700
- }
701
- function createFilterMethods(state, addCondition, self) {
702
- return {
703
- eq(column, value) {
704
- if (shouldUseUuidTextComparison(column, value)) {
705
- addCondition("eq", column, value, { columnCast: "text" });
706
- } else {
707
- addCondition("eq", column, value);
708
- }
709
- return self;
710
- },
711
- eqCast(column, value, cast) {
712
- addCondition("eq", column, value, { valueCast: cast });
713
- return self;
714
- },
715
- eqUuid(column, value) {
716
- addCondition("eq", column, value, { valueCast: "uuid" });
717
- return self;
718
- },
719
- match(filters) {
720
- Object.entries(filters).forEach(([column, value]) => {
721
- if (shouldUseUuidTextComparison(column, value)) {
722
- addCondition("eq", column, value, { columnCast: "text" });
723
- } else {
724
- addCondition("eq", column, value);
725
- }
710
+ try {
711
+ const response = await fetcher(url, requestInit);
712
+ const rawText = await response.text();
713
+ const requestId = resolveRequestId2(response.headers);
714
+ const parsedBody = parseResponseBody2(rawText ?? "", response.headers.get("content-type"));
715
+ if (parsedBody.parseFailed) {
716
+ const details = toErrorDetails({
717
+ code: "INVALID_JSON",
718
+ message: "Auth server returned malformed JSON",
719
+ status: response.status,
720
+ endpoint: context.endpoint,
721
+ method: context.method,
722
+ requestId,
723
+ hint: "Verify the auth endpoint response body is valid JSON.",
724
+ cause: rawText.slice(0, 300)
726
725
  });
727
- return self;
728
- },
729
- range(from, to) {
730
- state.offset = from;
731
- state.limit = to - from + 1;
732
- return self;
733
- },
734
- limit(count) {
735
- state.limit = count;
736
- return self;
737
- },
738
- offset(count) {
739
- state.offset = count;
740
- return self;
741
- },
742
- currentPage(value) {
743
- state.currentPage = value;
744
- return self;
745
- },
746
- pageSize(value) {
747
- state.pageSize = value;
748
- return self;
749
- },
750
- totalPages(value) {
751
- state.totalPages = value;
752
- return self;
753
- },
754
- order(column, options) {
755
- state.order = {
756
- field: column,
757
- direction: options?.ascending === false ? "descending" : "ascending"
726
+ return {
727
+ ok: false,
728
+ status: response.status,
729
+ data: null,
730
+ error: details.message,
731
+ errorDetails: details,
732
+ raw: parsedBody.parsed
758
733
  };
759
- return self;
760
- },
761
- gt(column, value) {
762
- addCondition("gt", column, value);
763
- return self;
764
- },
765
- gte(column, value) {
766
- addCondition("gte", column, value);
767
- return self;
768
- },
769
- lt(column, value) {
770
- addCondition("lt", column, value);
771
- return self;
772
- },
773
- lte(column, value) {
774
- addCondition("lte", column, value);
775
- return self;
776
- },
777
- neq(column, value) {
778
- addCondition("neq", column, value);
779
- return self;
780
- },
781
- like(column, value) {
782
- addCondition("like", column, value);
783
- return self;
784
- },
785
- ilike(column, value) {
786
- addCondition("ilike", column, value);
787
- return self;
788
- },
789
- is(column, value) {
790
- addCondition("is", column, value);
791
- return self;
792
- },
793
- in(column, values) {
794
- addCondition("in", column, values);
795
- return self;
796
- },
797
- contains(column, values) {
798
- addCondition("contains", column, values);
799
- return self;
800
- },
801
- containedBy(column, values) {
802
- addCondition("containedBy", column, values);
803
- return self;
804
- },
805
- not(columnOrExpression, operator, value) {
806
- if (operator != null && value !== void 0) {
807
- addCondition("not", void 0, `${columnOrExpression}.${operator}.${stringifyFilterValue(value)}`);
808
- } else {
809
- addCondition("not", void 0, columnOrExpression);
810
- }
811
- return self;
812
- },
813
- or(expression) {
814
- addCondition("or", void 0, expression);
815
- return self;
816
734
  }
817
- };
735
+ const parsed = parsedBody.parsed;
736
+ if (!response.ok) {
737
+ const details = toErrorDetails({
738
+ code: "HTTP_ERROR",
739
+ message: resolveErrorMessage2(
740
+ parsed,
741
+ `Auth endpoint ${context.method} ${context.endpoint} failed with status ${response.status}`
742
+ ),
743
+ status: response.status,
744
+ endpoint: context.endpoint,
745
+ method: context.method,
746
+ requestId
747
+ });
748
+ return {
749
+ ok: false,
750
+ status: response.status,
751
+ data: null,
752
+ error: details.message,
753
+ errorDetails: details,
754
+ raw: parsed
755
+ };
756
+ }
757
+ return {
758
+ ok: true,
759
+ status: response.status,
760
+ data: parsed ?? null,
761
+ error: null,
762
+ errorDetails: null,
763
+ raw: parsed
764
+ };
765
+ } catch (callError) {
766
+ const message = callError instanceof Error ? callError.message : String(callError);
767
+ const details = toErrorDetails({
768
+ code: "NETWORK_ERROR",
769
+ message: `Network error while calling ${context.method} ${context.endpoint}: ${message}`,
770
+ status: 0,
771
+ endpoint: context.endpoint,
772
+ method: context.method,
773
+ cause: message,
774
+ hint: "Check auth server URL, DNS, and network reachability."
775
+ });
776
+ return {
777
+ ok: false,
778
+ status: 0,
779
+ data: null,
780
+ error: details.message,
781
+ errorDetails: details,
782
+ raw: null
783
+ };
784
+ }
818
785
  }
819
- function toRpcSelect(columns) {
820
- if (!columns) return void 0;
821
- return Array.isArray(columns) ? columns.join(",") : columns;
786
+ function executePostWithCompatibleInput(config, context, input, options) {
787
+ const { payload, fetchOptions } = extractFetchOptions(input);
788
+ const mergedOptions = mergeCallOptions(fetchOptions, options);
789
+ return callAuthEndpoint(config, context, payload ?? {}, void 0, mergedOptions);
822
790
  }
823
- function createRpcFilterMethods(filters, self) {
824
- const addFilter = (operator, column, value) => {
825
- filters.push({ column, operator, value });
826
- };
827
- return {
828
- eq(column, value) {
829
- addFilter("eq", column, value);
830
- return self;
831
- },
832
- neq(column, value) {
833
- addFilter("neq", column, value);
834
- return self;
835
- },
836
- gt(column, value) {
837
- addFilter("gt", column, value);
838
- return self;
839
- },
840
- gte(column, value) {
841
- addFilter("gte", column, value);
842
- return self;
843
- },
844
- lt(column, value) {
845
- addFilter("lt", column, value);
846
- return self;
847
- },
848
- lte(column, value) {
849
- addFilter("lte", column, value);
850
- return self;
851
- },
852
- like(column, value) {
853
- addFilter("like", column, value);
854
- return self;
855
- },
856
- ilike(column, value) {
857
- addFilter("ilike", column, value);
858
- return self;
859
- },
860
- is(column, value) {
861
- addFilter("is", column, value);
862
- return self;
863
- },
864
- in(column, values) {
865
- addFilter("in", column, values);
866
- return self;
867
- }
868
- };
791
+ function executePostWithOptionalInput(config, context, input, options) {
792
+ const { fetchOptions } = extractFetchOptions(input);
793
+ const mergedOptions = mergeCallOptions(fetchOptions, options);
794
+ return callAuthEndpoint(config, context, {}, void 0, mergedOptions);
869
795
  }
870
- function createRpcBuilder(functionName, args, baseOptions, client) {
871
- const state = {
872
- filters: []
796
+ function executeGetWithCompatibleInput(config, context, input, options) {
797
+ const { fetchOptions } = extractFetchOptions(input);
798
+ const mergedOptions = mergeCallOptions(fetchOptions, options);
799
+ return callAuthEndpoint(config, context, void 0, void 0, mergedOptions);
800
+ }
801
+ function executeGetWithQueryCompatibleInput(config, context, input, options) {
802
+ const { payload, fetchOptions } = extractFetchOptions(input);
803
+ const mergedOptions = mergeCallOptions(fetchOptions, options);
804
+ const query = payload?.query;
805
+ return callAuthEndpoint(
806
+ config,
807
+ context,
808
+ void 0,
809
+ query,
810
+ mergedOptions
811
+ );
812
+ }
813
+ function createAuthClient(config = {}) {
814
+ const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
815
+ const resolvedConfig = {
816
+ ...config,
817
+ baseUrl: normalizedBaseUrl
873
818
  };
874
- let selectedColumns;
875
- let selectedOptions;
876
- let promise = null;
877
- const executeRpc = async (columns, options) => {
878
- const mergedOptions = mergeOptions(baseOptions, options);
879
- const payload = {
880
- function: functionName,
881
- args,
882
- schema: mergedOptions?.schema,
883
- select: toRpcSelect(columns),
884
- filters: state.filters.length ? [...state.filters] : void 0,
885
- count: mergedOptions?.count,
886
- head: mergedOptions?.head,
887
- limit: state.limit,
888
- offset: state.offset,
889
- order: state.order
890
- };
891
- const response = await client.rpcGateway(payload, mergedOptions);
892
- return formatResult(response);
819
+ const request = (input, options) => {
820
+ const method = input.method ?? (input.body !== void 0 ? "POST" : inferDefaultMethod(input.endpoint));
821
+ const mergedOptions = mergeCallOptions(input.fetchOptions, options);
822
+ return callAuthEndpoint(
823
+ resolvedConfig,
824
+ { endpoint: input.endpoint, method },
825
+ input.body,
826
+ input.query,
827
+ mergedOptions
828
+ );
893
829
  };
894
- const run = (columns, options) => {
895
- const payloadColumns = columns ?? selectedColumns;
896
- const payloadOptions = options ?? selectedOptions;
897
- if (!promise) {
898
- promise = executeRpc(payloadColumns, payloadOptions);
899
- }
900
- return promise;
830
+ const postGeneric = (endpoint, input, options) => {
831
+ const { payload, fetchOptions } = extractFetchOptions(input);
832
+ return request(
833
+ {
834
+ endpoint,
835
+ method: "POST",
836
+ body: payload ?? {},
837
+ fetchOptions
838
+ },
839
+ options
840
+ );
901
841
  };
902
- const builder = {};
903
- const filterMethods = createRpcFilterMethods(state.filters, builder);
904
- Object.assign(builder, filterMethods, {
905
- select(columns = selectedColumns, options) {
906
- selectedColumns = columns;
907
- selectedOptions = options ?? selectedOptions;
908
- return run(columns, options);
909
- },
910
- async single(columns, options) {
911
- const result = await run(columns, options);
912
- return toSingleResult(result);
913
- },
914
- maybeSingle(columns, options) {
915
- return builder.single(columns, options);
916
- },
917
- order(column, options) {
918
- state.order = { column, ascending: options?.ascending ?? true };
919
- return builder;
920
- },
921
- limit(count) {
922
- state.limit = count;
923
- return builder;
924
- },
925
- offset(count) {
926
- state.offset = count;
927
- return builder;
928
- },
929
- range(from, to) {
930
- state.offset = from;
931
- state.limit = to - from + 1;
932
- return builder;
933
- },
934
- then(onfulfilled, onrejected) {
935
- return run(selectedColumns, selectedOptions).then(onfulfilled, onrejected);
936
- },
937
- catch(onrejected) {
938
- return run(selectedColumns, selectedOptions).catch(onrejected);
939
- },
940
- finally(onfinally) {
941
- return run(selectedColumns, selectedOptions).finally(onfinally);
942
- }
943
- });
944
- return builder;
945
- }
946
- function createTableBuilder(tableName, client) {
947
- const state = {
948
- conditions: []
842
+ const getGeneric = (endpoint, input, options) => {
843
+ const { fetchOptions } = extractFetchOptions(input);
844
+ return request(
845
+ {
846
+ endpoint,
847
+ method: "GET",
848
+ fetchOptions
849
+ },
850
+ options
851
+ );
949
852
  };
950
- const addCondition = (operator, column, value, hints) => {
951
- const condition = { operator };
952
- if (column) {
953
- condition.column = column;
954
- if (operator === "eq") {
955
- condition.eq_column = column;
956
- }
957
- }
958
- if (value !== void 0) {
959
- condition.value = value;
960
- if (operator === "eq") {
961
- condition.eq_value = value;
962
- }
853
+ const getWithQuery = (endpoint, input, options) => {
854
+ const { payload, fetchOptions } = extractFetchOptions(input);
855
+ const query = payload?.query;
856
+ return request(
857
+ {
858
+ endpoint,
859
+ method: "GET",
860
+ query,
861
+ fetchOptions
862
+ },
863
+ options
864
+ );
865
+ };
866
+ const listUserEmailsWithFallback = async (input, options) => {
867
+ const primary = await getWithQuery(
868
+ "/email/list",
869
+ input,
870
+ options
871
+ );
872
+ if (primary.ok || primary.status !== 404 || primary.errorDetails?.code !== "HTTP_ERROR") {
873
+ return primary;
963
874
  }
964
- if (hints?.valueCast) {
965
- condition.value_cast = hints.valueCast;
966
- if (operator === "eq") {
967
- condition.eq_value_cast = hints.valueCast;
968
- }
875
+ return getWithQuery(
876
+ "/email-list",
877
+ input,
878
+ options
879
+ );
880
+ };
881
+ const healthWithFallback = async (input, options) => {
882
+ const primary = await getGeneric("/health", input, options);
883
+ if (primary.ok || primary.status !== 404 || primary.errorDetails?.code !== "HTTP_ERROR") {
884
+ return primary;
969
885
  }
970
- if (hints?.columnCast) {
971
- condition.column_cast = hints.columnCast;
972
- if (operator === "eq") {
973
- condition.eq_column_cast = hints.columnCast;
974
- }
886
+ const fallback = await getGeneric("/ok", input, options);
887
+ if (!fallback.ok) {
888
+ return {
889
+ ...fallback,
890
+ data: null
891
+ };
975
892
  }
976
- state.conditions.push(condition);
977
- };
978
- const builder = {};
979
- const filterMethods = createFilterMethods(state, addCondition, builder);
980
- const runSelect = async (columns = DEFAULT_COLUMNS, options) => {
981
- const conditions = state.conditions.length ? state.conditions.map((condition) => ({ ...condition })) : void 0;
982
- const hasTypedEqualityComparison = conditions?.some(
983
- (condition) => condition.operator === "eq" && (condition.value_cast !== void 0 || condition.column_cast !== void 0)
984
- ) ?? false;
985
- if (hasTypedEqualityComparison && !options?.head && !options?.count && conditions) {
986
- const query = buildTypedSelectQuery({
987
- tableName,
988
- columns,
989
- conditions,
990
- limit: state.limit,
991
- offset: state.offset,
992
- currentPage: state.currentPage,
993
- pageSize: state.pageSize,
994
- order: state.order
995
- });
996
- if (query) {
997
- const queryResponse = await client.queryGateway({ query }, options);
998
- return formatResult(queryResponse);
893
+ const fallbackStatus = isRecord2(fallback.data) && typeof fallback.data.ok === "boolean" ? fallback.data.ok ? "ok" : "error" : "ok";
894
+ return {
895
+ ...fallback,
896
+ data: {
897
+ status: fallbackStatus
999
898
  }
1000
- }
1001
- const payload = {
1002
- table_name: tableName,
1003
- columns,
1004
- conditions,
1005
- limit: state.limit,
1006
- offset: state.offset,
1007
- current_page: state.currentPage,
1008
- page_size: state.pageSize,
1009
- total_pages: state.totalPages,
1010
- sort_by: state.order,
1011
- strip_nulls: options?.stripNulls ?? true,
1012
- count: options?.count,
1013
- head: options?.head
1014
899
  };
1015
- const response = await client.fetchGateway(payload, options);
1016
- return formatResult(response);
1017
- };
1018
- const createSelectChain = (columns, options) => {
1019
- const chain = {};
1020
- const filterMethods2 = createFilterMethods(state, addCondition, chain);
1021
- Object.assign(chain, filterMethods2, {
1022
- async single(cols, opts) {
1023
- const r = await runSelect(cols ?? columns, opts ?? options);
1024
- return toSingleResult(r);
1025
- },
1026
- maybeSingle(cols, opts) {
1027
- return chain.single(cols, opts);
1028
- },
1029
- then(onfulfilled, onrejected) {
1030
- return runSelect(columns, options).then(onfulfilled, onrejected);
1031
- },
1032
- catch(onrejected) {
1033
- return runSelect(columns, options).catch(onrejected);
1034
- },
1035
- finally(onfinally) {
1036
- return runSelect(columns, options).finally(onfinally);
1037
- }
1038
- });
1039
- return chain;
1040
900
  };
1041
- Object.assign(builder, filterMethods, {
1042
- reset() {
1043
- state.conditions = [];
901
+ const signOut = (input, options) => executePostWithOptionalInput(
902
+ resolvedConfig,
903
+ { endpoint: "/sign-out", method: "POST" },
904
+ input,
905
+ options
906
+ );
907
+ const revokeSessions = (input, options) => executePostWithOptionalInput(
908
+ resolvedConfig,
909
+ { endpoint: "/revoke-sessions", method: "POST" },
910
+ input,
911
+ options
912
+ );
913
+ const revokeOtherSessions = (input, options) => executePostWithOptionalInput(
914
+ resolvedConfig,
915
+ { endpoint: "/revoke-other-sessions", method: "POST" },
916
+ input,
917
+ options
918
+ );
919
+ const revokeSession = (input, options) => executePostWithCompatibleInput(
920
+ resolvedConfig,
921
+ { endpoint: "/revoke-session", method: "POST" },
922
+ input,
923
+ options
924
+ );
925
+ const deleteUser = (input, options) => {
926
+ const { payload, fetchOptions } = extractFetchOptions(input);
927
+ const mergedOptions = mergeCallOptions(fetchOptions, options);
928
+ return callAuthEndpoint(
929
+ resolvedConfig,
930
+ { endpoint: "/delete-user", method: "POST" },
931
+ payload ?? {},
932
+ void 0,
933
+ mergedOptions
934
+ );
935
+ };
936
+ const deleteUserCallback = (input, options) => {
937
+ const { payload, fetchOptions } = extractFetchOptions(input);
938
+ const mergedOptions = mergeCallOptions(fetchOptions, options);
939
+ const query = payload ?? {};
940
+ return callAuthEndpoint(
941
+ resolvedConfig,
942
+ { endpoint: "/delete-user/callback", method: "GET" },
943
+ void 0,
944
+ {
945
+ token: query.token,
946
+ callbackURL: query.callbackURL
947
+ },
948
+ mergedOptions
949
+ );
950
+ };
951
+ const resolveResetPasswordToken = (input, options) => {
952
+ const { payload, fetchOptions } = extractFetchOptions(input);
953
+ const mergedOptions = mergeCallOptions(fetchOptions, options);
954
+ const query = payload;
955
+ const token = query?.token?.trim();
956
+ if (!token) {
957
+ throw new Error("resolveResetPasswordToken requires a non-empty token");
958
+ }
959
+ const endpoint = `/reset-password/${encodeURIComponent(token)}`;
960
+ return callAuthEndpoint(
961
+ resolvedConfig,
962
+ { endpoint, method: "GET" },
963
+ void 0,
964
+ query?.callbackURL ? { callbackURL: query.callbackURL } : void 0,
965
+ mergedOptions
966
+ );
967
+ };
968
+ const organization = {
969
+ create: (input, options) => executePostWithCompatibleInput(
970
+ resolvedConfig,
971
+ { endpoint: "/organization/create", method: "POST" },
972
+ input,
973
+ options
974
+ ),
975
+ update: (input, options) => executePostWithCompatibleInput(
976
+ resolvedConfig,
977
+ { endpoint: "/organization/update", method: "POST" },
978
+ input,
979
+ options
980
+ ),
981
+ delete: (input, options) => executePostWithCompatibleInput(
982
+ resolvedConfig,
983
+ { endpoint: "/organization/delete", method: "POST" },
984
+ input,
985
+ options
986
+ ),
987
+ setActive: (input, options) => executePostWithCompatibleInput(
988
+ resolvedConfig,
989
+ { endpoint: "/organization/set-active", method: "POST" },
990
+ input,
991
+ options
992
+ ),
993
+ list: (input, options) => getGeneric(
994
+ "/organization/list",
995
+ input,
996
+ options
997
+ ),
998
+ getFull: (input, options) => executeGetWithQueryCompatibleInput(
999
+ resolvedConfig,
1000
+ { endpoint: "/organization/get-full-organization", method: "GET" },
1001
+ input,
1002
+ options
1003
+ ),
1004
+ checkSlug: (input, options) => executePostWithCompatibleInput(
1005
+ resolvedConfig,
1006
+ { endpoint: "/organization/check-slug", method: "POST" },
1007
+ input,
1008
+ options
1009
+ ),
1010
+ leave: (input, options) => executePostWithCompatibleInput(
1011
+ resolvedConfig,
1012
+ { endpoint: "/organization/leave", method: "POST" },
1013
+ input,
1014
+ options
1015
+ ),
1016
+ listUserInvitations: (input, options) => executeGetWithQueryCompatibleInput(
1017
+ resolvedConfig,
1018
+ { endpoint: "/organization/list-user-invitations", method: "GET" },
1019
+ input,
1020
+ options
1021
+ ),
1022
+ hasPermission: (input, options) => postGeneric(
1023
+ "/organization/has-permission",
1024
+ input,
1025
+ options
1026
+ ),
1027
+ invitation: {
1028
+ cancel: (input, options) => executePostWithCompatibleInput(
1029
+ resolvedConfig,
1030
+ { endpoint: "/organization/cancel-invitation", method: "POST" },
1031
+ input,
1032
+ options
1033
+ ),
1034
+ accept: (input, options) => executePostWithCompatibleInput(
1035
+ resolvedConfig,
1036
+ { endpoint: "/organization/accept-invitation", method: "POST" },
1037
+ input,
1038
+ options
1039
+ ),
1040
+ get: (input, options) => executeGetWithQueryCompatibleInput(
1041
+ resolvedConfig,
1042
+ { endpoint: "/organization/get-invitation", method: "GET" },
1043
+ input,
1044
+ options
1045
+ ),
1046
+ reject: (input, options) => executePostWithCompatibleInput(
1047
+ resolvedConfig,
1048
+ { endpoint: "/organization/reject-invitation", method: "POST" },
1049
+ input,
1050
+ options
1051
+ ),
1052
+ list: (input, options) => executeGetWithQueryCompatibleInput(
1053
+ resolvedConfig,
1054
+ { endpoint: "/organization/list-invitations", method: "GET" },
1055
+ input,
1056
+ options
1057
+ )
1058
+ },
1059
+ member: {
1060
+ remove: (input, options) => executePostWithCompatibleInput(
1061
+ resolvedConfig,
1062
+ { endpoint: "/organization/remove-member", method: "POST" },
1063
+ input,
1064
+ options
1065
+ ),
1066
+ updateRole: (input, options) => executePostWithCompatibleInput(
1067
+ resolvedConfig,
1068
+ { endpoint: "/organization/update-member-role", method: "POST" },
1069
+ input,
1070
+ options
1071
+ ),
1072
+ invite: (input, options) => executePostWithCompatibleInput(
1073
+ resolvedConfig,
1074
+ { endpoint: "/organization/invite-member", method: "POST" },
1075
+ input,
1076
+ options
1077
+ ),
1078
+ getActive: (input, options) => executeGetWithCompatibleInput(
1079
+ resolvedConfig,
1080
+ { endpoint: "/organization/get-active-member", method: "GET" },
1081
+ input,
1082
+ options
1083
+ ),
1084
+ list: (input, options) => executeGetWithQueryCompatibleInput(
1085
+ resolvedConfig,
1086
+ { endpoint: "/organization/list-members", method: "GET" },
1087
+ input,
1088
+ options
1089
+ )
1090
+ }
1091
+ };
1092
+ const authResetPassword = Object.assign(
1093
+ (input, options) => executePostWithCompatibleInput(
1094
+ resolvedConfig,
1095
+ { endpoint: "/reset-password", method: "POST" },
1096
+ input,
1097
+ options
1098
+ ),
1099
+ {
1100
+ token: resolveResetPasswordToken
1101
+ }
1102
+ );
1103
+ const sessionRevokeBinding = (input, options) => {
1104
+ if (Array.isArray(input)) {
1105
+ if (input.length === 0) {
1106
+ throw new Error("session.revoke requires at least one session token");
1107
+ }
1108
+ if (input.length === 1) {
1109
+ return revokeSession(input[0], options);
1110
+ }
1111
+ return revokeSessions(void 0, options);
1112
+ }
1113
+ const parsed = input;
1114
+ const tokens = Array.isArray(parsed.tokens) ? parsed.tokens.filter((token2) => token2.trim().length > 0) : void 0;
1115
+ if (tokens && tokens.length > 1) {
1116
+ return revokeSessions(
1117
+ parsed.fetchOptions ? { fetchOptions: parsed.fetchOptions } : void 0,
1118
+ options
1119
+ );
1120
+ }
1121
+ if (tokens && tokens.length === 1) {
1122
+ return revokeSession(
1123
+ { token: tokens[0], fetchOptions: parsed.fetchOptions },
1124
+ options
1125
+ );
1126
+ }
1127
+ const token = parsed.token?.trim();
1128
+ if (!token) {
1129
+ throw new Error("session.revoke requires a non-empty token or a non-empty token list");
1130
+ }
1131
+ return revokeSession(
1132
+ {
1133
+ token,
1134
+ fetchOptions: parsed.fetchOptions
1135
+ },
1136
+ options
1137
+ );
1138
+ };
1139
+ const adminUserSessionRevokeBinding = (input, options) => {
1140
+ const requireUserId = (userId) => {
1141
+ const trimmed = String(userId ?? "").trim();
1142
+ if (!trimmed) {
1143
+ throw new Error("admin.user.session.revoke requires a non-empty userId");
1144
+ }
1145
+ return trimmed;
1146
+ };
1147
+ const requireSinglePluralUserId = (sessions2) => {
1148
+ const uniqueUserIds = [...new Set(sessions2.map((session) => requireUserId(session.userId)))];
1149
+ if (uniqueUserIds.length !== 1) {
1150
+ throw new Error("admin.user.session.revoke requires the same userId across plural payloads");
1151
+ }
1152
+ return { userId: uniqueUserIds[0] };
1153
+ };
1154
+ if (Array.isArray(input)) {
1155
+ if (input.length === 0) {
1156
+ throw new Error("admin.user.session.revoke requires at least one payload item");
1157
+ }
1158
+ if (input.length === 1) {
1159
+ return postGeneric(
1160
+ "/admin/revoke-user-session",
1161
+ {
1162
+ ...input[0],
1163
+ userId: requireUserId(input[0].userId)
1164
+ },
1165
+ options
1166
+ );
1167
+ }
1168
+ return postGeneric(
1169
+ "/admin/revoke-user-sessions",
1170
+ requireSinglePluralUserId(input),
1171
+ options
1172
+ );
1173
+ }
1174
+ const parsed = input;
1175
+ const sessions = parsed.sessions;
1176
+ if (sessions && sessions.length === 0) {
1177
+ throw new Error("admin.user.session.revoke requires at least one payload item");
1178
+ }
1179
+ if (sessions && sessions.length === 1) {
1180
+ return postGeneric(
1181
+ "/admin/revoke-user-session",
1182
+ {
1183
+ ...sessions[0],
1184
+ userId: requireUserId(sessions[0].userId),
1185
+ fetchOptions: parsed.fetchOptions
1186
+ },
1187
+ options
1188
+ );
1189
+ }
1190
+ if (sessions && sessions.length > 1) {
1191
+ return postGeneric(
1192
+ "/admin/revoke-user-sessions",
1193
+ {
1194
+ ...requireSinglePluralUserId(sessions),
1195
+ fetchOptions: parsed.fetchOptions
1196
+ },
1197
+ options
1198
+ );
1199
+ }
1200
+ const normalizedUserId = requireUserId(parsed.userId);
1201
+ if (!parsed.sessionToken) {
1202
+ return postGeneric(
1203
+ "/admin/revoke-user-sessions",
1204
+ {
1205
+ userId: normalizedUserId,
1206
+ fetchOptions: parsed.fetchOptions
1207
+ },
1208
+ options
1209
+ );
1210
+ }
1211
+ return postGeneric(
1212
+ "/admin/revoke-user-session",
1213
+ {
1214
+ ...parsed,
1215
+ userId: normalizedUserId
1216
+ },
1217
+ options
1218
+ );
1219
+ };
1220
+ const auth = {
1221
+ getSession: (input, options) => getGeneric("/get-session", input, options),
1222
+ signOut,
1223
+ forgetPassword: (input, options) => postGeneric("/forget-password", input, options),
1224
+ resetPassword: authResetPassword,
1225
+ setPassword: (input, options) => postGeneric("/set-password", input, options),
1226
+ verifyEmail: (input, options) => {
1227
+ const queryInput = {
1228
+ query: {
1229
+ token: input.token,
1230
+ callbackURL: input.callbackURL
1231
+ },
1232
+ fetchOptions: input.fetchOptions
1233
+ };
1234
+ return getWithQuery(
1235
+ "/verify-email",
1236
+ queryInput,
1237
+ options
1238
+ );
1239
+ },
1240
+ sendVerificationEmail: (input, options) => postGeneric("/send-verification-email", input, options),
1241
+ changeEmail: (input, options) => postGeneric("/change-email", input, options),
1242
+ changeEmailVerify: (input, options) => getWithQuery("/change-email/verify", input, options),
1243
+ deleteUserVerify: (input, options) => getWithQuery("/delete-user/verify", input, options),
1244
+ changePassword: (input, options) => postGeneric("/change-password", input, options),
1245
+ user: {
1246
+ update: (input, options) => postGeneric("/update-user", input, options),
1247
+ delete: (input, options) => postGeneric("/delete-user", input, options),
1248
+ email: {
1249
+ list: listUserEmailsWithFallback
1250
+ }
1251
+ },
1252
+ session: {
1253
+ list: (input, options) => getGeneric("/list-sessions", input, options),
1254
+ revoke: sessionRevokeBinding,
1255
+ revokeOther: revokeOtherSessions
1256
+ },
1257
+ social: {
1258
+ link: (input, options) => postGeneric("/link-social", input, options)
1259
+ },
1260
+ account: {
1261
+ list: (input, options) => getGeneric("/list-accounts", input, options),
1262
+ unlink: (input, options) => postGeneric("/unlink-account", input, options)
1263
+ },
1264
+ deleteUser: {
1265
+ callback: deleteUserCallback
1266
+ },
1267
+ refreshToken: (input, options) => postGeneric("/refresh-token", input, options),
1268
+ getAccessToken: (input, options) => postGeneric("/get-access-token", input, options),
1269
+ health: healthWithFallback,
1270
+ ok: (input, options) => getGeneric("/ok", input, options),
1271
+ error: (input, options) => getGeneric("/error", input, options),
1272
+ twoFactor: {
1273
+ getTotpUri: (input, options) => postGeneric("/two-factor/get-totp-uri", input, options),
1274
+ verifyTotp: (input, options) => postGeneric("/two-factor/verify-totp", input, options),
1275
+ sendOtp: (input, options) => postGeneric("/two-factor/send-otp", input, options),
1276
+ verifyOtp: (input, options) => postGeneric("/two-factor/verify-otp", input, options),
1277
+ verifyBackupCode: (input, options) => postGeneric("/two-factor/verify-backup-code", input, options),
1278
+ generateBackupCodes: (input, options) => executePostWithCompatibleInput(
1279
+ resolvedConfig,
1280
+ { endpoint: "/two-factor/generate-backup-codes", method: "POST" },
1281
+ input,
1282
+ options
1283
+ ),
1284
+ enable: (input, options) => postGeneric("/two-factor/enable", input, options),
1285
+ disable: (input, options) => postGeneric("/two-factor/disable", input, options)
1286
+ },
1287
+ passkey: {
1288
+ generateRegisterOptions: (input, options) => getGeneric("/passkey/generate-register-options", input, options),
1289
+ generateAuthenticateOptions: (input, options) => postGeneric("/passkey/generate-authenticate-options", input, options),
1290
+ verifyRegistration: (input, options) => postGeneric("/passkey/verify-registration", input, options),
1291
+ verifyAuthentication: (input, options) => postGeneric("/passkey/verify-authentication", input, options),
1292
+ listUserPasskeys: (input, options) => getGeneric("/passkey/list-user-passkeys", input, options),
1293
+ deletePasskey: (input, options) => postGeneric("/passkey/delete-passkey", input, options),
1294
+ updatePasskey: (input, options) => postGeneric("/passkey/update-passkey", input, options),
1295
+ getRelatedOrigins: (input, options) => getGeneric("/.well-known/webauthn", input, options)
1296
+ },
1297
+ admin: {
1298
+ role: {
1299
+ set: (input, options) => postGeneric("/admin/set-role", input, options)
1300
+ },
1301
+ user: {
1302
+ list: (input, options) => getWithQuery("/admin/list-users", input, options),
1303
+ create: (input, options) => postGeneric("/admin/create-user", input, options),
1304
+ unban: (input, options) => postGeneric("/admin/unban-user", input, options),
1305
+ ban: (input, options) => postGeneric("/admin/ban-user", input, options),
1306
+ impersonate: (input, options) => postGeneric("/admin/impersonate-user", input, options),
1307
+ stopImpersonating: (input, options) => postGeneric("/admin/stop-impersonating", input, options),
1308
+ remove: (input, options) => postGeneric("/admin/remove-user", input, options),
1309
+ setPassword: (input, options) => postGeneric("/admin/set-user-password", input, options),
1310
+ session: {
1311
+ list: (input, options) => postGeneric("/admin/list-user-sessions", input, options),
1312
+ revoke: adminUserSessionRevokeBinding
1313
+ }
1314
+ },
1315
+ hasPermission: (input, options) => postGeneric("/admin/has-permission", input, options),
1316
+ apiKey: {
1317
+ create: (input, options) => postGeneric("/admin/api-key/create", input, options)
1318
+ },
1319
+ athenaClient: {
1320
+ create: (input, options) => postGeneric("/admin/athena-client/create", input, options),
1321
+ list: (input, options) => getWithQuery("/admin/athena-client/list", input, options)
1322
+ },
1323
+ auditLog: {
1324
+ list: (input, options) => getWithQuery("/admin/audit-log/list", input, options)
1325
+ },
1326
+ email: {
1327
+ list: (input, options) => getWithQuery("/admin/email/list", input, options),
1328
+ get: (input, options) => getWithQuery("/admin/email/get", input, options),
1329
+ create: (input, options) => postGeneric("/admin/email/create", input, options),
1330
+ update: (input, options) => postGeneric("/admin/email/update", input, options),
1331
+ delete: (input, options) => postGeneric("/admin/email/delete", input, options),
1332
+ failure: {
1333
+ list: (input, options) => getWithQuery("/admin/email-failure/list", input, options),
1334
+ get: (input, options) => getWithQuery("/admin/email-failure/get", input, options),
1335
+ create: (input, options) => postGeneric("/admin/email-failure/create", input, options),
1336
+ update: (input, options) => postGeneric("/admin/email-failure/update", input, options),
1337
+ delete: (input, options) => postGeneric("/admin/email-failure/delete", input, options)
1338
+ },
1339
+ template: {
1340
+ list: (input, options) => getWithQuery("/admin/email-template/list", input, options),
1341
+ get: (input, options) => getWithQuery("/admin/email-template/get", input, options),
1342
+ create: (input, options) => postGeneric("/admin/email-template/create", input, options),
1343
+ update: (input, options) => postGeneric("/admin/email-template/update", input, options),
1344
+ delete: (input, options) => postGeneric("/admin/email-template/delete", input, options)
1345
+ }
1346
+ },
1347
+ emailTemplate: {
1348
+ get: (input, options) => getWithQuery("/admin/email-template/get", input, options),
1349
+ create: (input, options) => postGeneric("/admin/email-template/create", input, options),
1350
+ delete: (input, options) => postGeneric("/admin/email-template/delete", input, options),
1351
+ list: (input, options) => getWithQuery("/admin/email-template/list", input, options),
1352
+ update: (input, options) => postGeneric("/admin/email-template/update", input, options)
1353
+ }
1354
+ },
1355
+ apiKey: {
1356
+ create: (input, options) => postGeneric("/api-key/create", input, options),
1357
+ get: (input, options) => getWithQuery("/api-key/get", input, options),
1358
+ update: (input, options) => postGeneric("/api-key/update", input, options),
1359
+ delete: (input, options) => postGeneric("/api-key/delete", input, options),
1360
+ list: (input, options) => getWithQuery("/api-key/list", input, options),
1361
+ verify: (input, options) => postGeneric("/api-key/verify", input, options),
1362
+ deleteAllExpired: (input, options) => executePostWithOptionalInput(
1363
+ resolvedConfig,
1364
+ { endpoint: "/api-key/delete-all-expired-api-keys", method: "POST" },
1365
+ input,
1366
+ options
1367
+ )
1368
+ },
1369
+ signIn: {
1370
+ email: (input, options) => postGeneric("/sign-in/email", input, options),
1371
+ username: (input, options) => postGeneric("/sign-in/username", input, options),
1372
+ social: (input, options) => postGeneric("/sign-in/social", input, options)
1373
+ },
1374
+ signUp: {
1375
+ email: (input, options) => postGeneric("/sign-up/email", input, options)
1376
+ },
1377
+ organization,
1378
+ callback: {
1379
+ provider: (input, options) => {
1380
+ const { payload, fetchOptions } = extractFetchOptions(input);
1381
+ const parsed = payload;
1382
+ const provider = String(parsed?.provider ?? "").trim();
1383
+ if (!provider) {
1384
+ throw new Error("callback.provider requires a non-empty provider value");
1385
+ }
1386
+ const code = String(parsed?.code ?? "").trim();
1387
+ const state = String(parsed?.state ?? "").trim();
1388
+ if (!code || !state) {
1389
+ throw new Error("callback.provider requires non-empty code and state values");
1390
+ }
1391
+ const endpoint = `/callback/${encodeURIComponent(provider)}`;
1392
+ return request({
1393
+ endpoint,
1394
+ method: "GET",
1395
+ query: {
1396
+ code,
1397
+ state
1398
+ },
1399
+ fetchOptions
1400
+ }, options);
1401
+ }
1402
+ }
1403
+ };
1404
+ return {
1405
+ baseUrl: normalizedBaseUrl,
1406
+ request,
1407
+ signIn: {
1408
+ email: (input, options) => executePostWithCompatibleInput(
1409
+ resolvedConfig,
1410
+ { endpoint: "/sign-in/email", method: "POST" },
1411
+ input,
1412
+ options
1413
+ ),
1414
+ username: (input, options) => executePostWithCompatibleInput(
1415
+ resolvedConfig,
1416
+ { endpoint: "/sign-in/username", method: "POST" },
1417
+ input,
1418
+ options
1419
+ ),
1420
+ social: (input, options) => executePostWithCompatibleInput(
1421
+ resolvedConfig,
1422
+ { endpoint: "/sign-in/social", method: "POST" },
1423
+ input,
1424
+ options
1425
+ )
1426
+ },
1427
+ signUp: {
1428
+ email: (input, options) => executePostWithCompatibleInput(
1429
+ resolvedConfig,
1430
+ { endpoint: "/sign-up/email", method: "POST" },
1431
+ input,
1432
+ options
1433
+ )
1434
+ },
1435
+ signOut,
1436
+ logout: signOut,
1437
+ getSession: (input, options) => executeGetWithCompatibleInput(
1438
+ resolvedConfig,
1439
+ { endpoint: "/get-session", method: "GET" },
1440
+ input,
1441
+ options
1442
+ ),
1443
+ listSessions: (input, options) => executeGetWithCompatibleInput(
1444
+ resolvedConfig,
1445
+ { endpoint: "/list-sessions", method: "GET" },
1446
+ input,
1447
+ options
1448
+ ),
1449
+ revokeSession,
1450
+ clearSession: revokeSession,
1451
+ revokeSessions,
1452
+ clearSessions: revokeSessions,
1453
+ revokeOtherSessions,
1454
+ clearOtherSessions: revokeOtherSessions,
1455
+ forgetPassword: (input, options) => executePostWithCompatibleInput(
1456
+ resolvedConfig,
1457
+ { endpoint: "/forget-password", method: "POST" },
1458
+ input,
1459
+ options
1460
+ ),
1461
+ resetPassword: (input, options) => executePostWithCompatibleInput(
1462
+ resolvedConfig,
1463
+ { endpoint: "/reset-password", method: "POST" },
1464
+ input,
1465
+ options
1466
+ ),
1467
+ resolveResetPasswordToken,
1468
+ verifyEmail: (input, options) => {
1469
+ const { payload, fetchOptions } = extractFetchOptions(input);
1470
+ const mergedOptions = mergeCallOptions(fetchOptions, options);
1471
+ const query = payload;
1472
+ return callAuthEndpoint(
1473
+ resolvedConfig,
1474
+ { endpoint: "/verify-email", method: "GET" },
1475
+ void 0,
1476
+ query ? {
1477
+ token: query.token,
1478
+ callbackURL: query.callbackURL
1479
+ } : void 0,
1480
+ mergedOptions
1481
+ );
1482
+ },
1483
+ sendVerificationEmail: (input, options) => executePostWithCompatibleInput(
1484
+ resolvedConfig,
1485
+ { endpoint: "/send-verification-email", method: "POST" },
1486
+ input,
1487
+ options
1488
+ ),
1489
+ changeEmail: (input, options) => executePostWithCompatibleInput(
1490
+ resolvedConfig,
1491
+ { endpoint: "/change-email", method: "POST" },
1492
+ input,
1493
+ options
1494
+ ),
1495
+ changePassword: (input, options) => executePostWithCompatibleInput(
1496
+ resolvedConfig,
1497
+ { endpoint: "/change-password", method: "POST" },
1498
+ input,
1499
+ options
1500
+ ),
1501
+ updateUser: (input, options) => executePostWithCompatibleInput(
1502
+ resolvedConfig,
1503
+ { endpoint: "/update-user", method: "POST" },
1504
+ input,
1505
+ options
1506
+ ),
1507
+ deleteUser,
1508
+ deleteUserCallback,
1509
+ linkSocial: (input, options) => executePostWithCompatibleInput(
1510
+ resolvedConfig,
1511
+ { endpoint: "/link-social", method: "POST" },
1512
+ input,
1513
+ options
1514
+ ),
1515
+ listAccounts: (input, options) => executeGetWithCompatibleInput(
1516
+ resolvedConfig,
1517
+ { endpoint: "/list-accounts", method: "GET" },
1518
+ input,
1519
+ options
1520
+ ),
1521
+ unlinkAccount: (input, options) => executePostWithCompatibleInput(
1522
+ resolvedConfig,
1523
+ { endpoint: "/unlink-account", method: "POST" },
1524
+ input,
1525
+ options
1526
+ ),
1527
+ refreshToken: (input, options) => executePostWithCompatibleInput(
1528
+ resolvedConfig,
1529
+ { endpoint: "/refresh-token", method: "POST" },
1530
+ input,
1531
+ options
1532
+ ),
1533
+ getAccessToken: (input, options) => executePostWithCompatibleInput(
1534
+ resolvedConfig,
1535
+ { endpoint: "/get-access-token", method: "POST" },
1536
+ input,
1537
+ options
1538
+ ),
1539
+ organization,
1540
+ auth
1541
+ };
1542
+ }
1543
+
1544
+ // src/client.ts
1545
+ var DEFAULT_COLUMNS = "*";
1546
+ var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
1547
+ var SAFE_CAST_PATTERN = /^[a-z_][a-z0-9_]*(?:\[\])?$/i;
1548
+ function formatResult(response) {
1549
+ const result = {
1550
+ data: response.data ?? null,
1551
+ error: response.error ?? null,
1552
+ errorDetails: response.errorDetails ?? null,
1553
+ status: response.status,
1554
+ raw: response.raw
1555
+ };
1556
+ if (response.count !== void 0) {
1557
+ result.count = response.count;
1558
+ }
1559
+ return result;
1560
+ }
1561
+ function toSingleResult(response) {
1562
+ const payload = response.data;
1563
+ const singleData = Array.isArray(payload) ? payload.length ? payload[0] : null : payload ?? null;
1564
+ return {
1565
+ ...response,
1566
+ data: singleData
1567
+ };
1568
+ }
1569
+ function mergeOptions(...options) {
1570
+ return options.reduce((acc, next) => {
1571
+ if (!next) return acc;
1572
+ return { ...acc, ...next };
1573
+ }, void 0);
1574
+ }
1575
+ function asAthenaJsonObject(value) {
1576
+ return value;
1577
+ }
1578
+ function asAthenaJsonObjectArray(values) {
1579
+ return values;
1580
+ }
1581
+ function createMutationQuery(executor, defaultColumns = DEFAULT_COLUMNS) {
1582
+ let selectedColumns = defaultColumns === null ? void 0 : defaultColumns;
1583
+ let selectedOptions;
1584
+ let promise = null;
1585
+ const run = (columns, options) => {
1586
+ const payloadColumns = columns ?? selectedColumns;
1587
+ const payloadOptions = options ?? selectedOptions;
1588
+ if (!promise) {
1589
+ promise = executor(payloadColumns, payloadOptions);
1590
+ }
1591
+ return promise;
1592
+ };
1593
+ const mutationQuery = {
1594
+ select(columns = selectedColumns, options) {
1595
+ selectedColumns = columns;
1596
+ selectedOptions = options ?? selectedOptions;
1597
+ return run(columns, options);
1598
+ },
1599
+ returning(columns = selectedColumns, options) {
1600
+ return mutationQuery.select(columns, options);
1601
+ },
1602
+ single(columns = selectedColumns, options) {
1603
+ selectedColumns = columns;
1604
+ selectedOptions = options ?? selectedOptions;
1605
+ return run(columns, options).then(toSingleResult);
1606
+ },
1607
+ maybeSingle(columns = selectedColumns, options) {
1608
+ return mutationQuery.single(columns, options);
1609
+ },
1610
+ then(onfulfilled, onrejected) {
1611
+ return run(selectedColumns, selectedOptions).then(onfulfilled, onrejected);
1612
+ },
1613
+ catch(onrejected) {
1614
+ return run(selectedColumns, selectedOptions).catch(onrejected);
1615
+ },
1616
+ finally(onfinally) {
1617
+ return run(selectedColumns, selectedOptions).finally(onfinally);
1618
+ }
1619
+ };
1620
+ return mutationQuery;
1621
+ }
1622
+ function getResourceId(state) {
1623
+ const candidate = state.conditions.find(
1624
+ (condition) => condition.operator === "eq" && (condition.column === "resource_id" || condition.column === "id")
1625
+ );
1626
+ return candidate?.value?.toString();
1627
+ }
1628
+ function stringifyFilterValue(value) {
1629
+ if (Array.isArray(value)) {
1630
+ return value.join(",");
1631
+ }
1632
+ return String(value);
1633
+ }
1634
+ function isUuidString(value) {
1635
+ return UUID_PATTERN.test(value.trim());
1636
+ }
1637
+ function isUuidIdentifierColumn(column) {
1638
+ return column === "id" || /(?:^|_)uuid(?:_|$)/i.test(column) || /_id$/i.test(column);
1639
+ }
1640
+ function shouldUseUuidTextComparison(column, value) {
1641
+ return typeof value === "string" && isUuidString(value) && isUuidIdentifierColumn(column);
1642
+ }
1643
+ function normalizeCast(cast) {
1644
+ const normalized = cast.trim().toLowerCase();
1645
+ if (!SAFE_CAST_PATTERN.test(normalized)) {
1646
+ throw new Error(`Invalid cast type "${cast}"`);
1647
+ }
1648
+ return normalized;
1649
+ }
1650
+ function escapeSqlStringLiteral(value) {
1651
+ return value.replace(/'/g, "''");
1652
+ }
1653
+ function toSqlLiteral(value) {
1654
+ if (value === null) return "NULL";
1655
+ if (typeof value === "number") return Number.isFinite(value) ? String(value) : "NULL";
1656
+ if (typeof value === "boolean") return value ? "TRUE" : "FALSE";
1657
+ return `'${escapeSqlStringLiteral(value)}'`;
1658
+ }
1659
+ function withCast(expression, cast) {
1660
+ if (!cast) return expression;
1661
+ return `${expression}::${normalizeCast(cast)}`;
1662
+ }
1663
+ function buildSelectColumnsClause(columns) {
1664
+ if (Array.isArray(columns)) {
1665
+ return columns.map((column) => quoteQualifiedIdentifier(column)).join(", ");
1666
+ }
1667
+ return quoteSelectColumnsExpression(columns);
1668
+ }
1669
+ function resolveTableNameForCall(tableName, schema) {
1670
+ if (!schema) return tableName;
1671
+ const normalizedSchema = schema.trim();
1672
+ if (!normalizedSchema) {
1673
+ throw new Error("schema option must be a non-empty string");
1674
+ }
1675
+ if (tableName.includes(".")) {
1676
+ if (tableName.startsWith(`${normalizedSchema}.`)) {
1677
+ return tableName;
1678
+ }
1679
+ throw new Error(
1680
+ `schema option "${normalizedSchema}" conflicts with schema-qualified table "${tableName}"`
1681
+ );
1682
+ }
1683
+ return `${normalizedSchema}.${tableName}`;
1684
+ }
1685
+ function conditionToSqlClause(condition) {
1686
+ if (!condition.column) return null;
1687
+ const column = withCast(quoteQualifiedIdentifier(condition.column), condition.column_cast);
1688
+ const value = condition.value;
1689
+ const sqlOperator = {
1690
+ eq: "=",
1691
+ neq: "!=",
1692
+ gt: ">",
1693
+ gte: ">=",
1694
+ lt: "<",
1695
+ lte: "<=",
1696
+ like: "LIKE",
1697
+ ilike: "ILIKE"
1698
+ };
1699
+ switch (condition.operator) {
1700
+ case "eq":
1701
+ case "neq":
1702
+ case "gt":
1703
+ case "gte":
1704
+ case "lt":
1705
+ case "lte":
1706
+ case "like":
1707
+ case "ilike": {
1708
+ if (Array.isArray(value) || value === void 0) return null;
1709
+ const rhs = withCast(toSqlLiteral(value), condition.value_cast);
1710
+ return `${column} ${sqlOperator[condition.operator]} ${rhs}`;
1711
+ }
1712
+ case "is": {
1713
+ if (value === null) return `${column} IS NULL`;
1714
+ if (value === true) return `${column} IS TRUE`;
1715
+ if (value === false) return `${column} IS FALSE`;
1716
+ return null;
1717
+ }
1718
+ case "in": {
1719
+ if (!Array.isArray(value)) return null;
1720
+ if (value.length === 0) return "FALSE";
1721
+ const values = value.map((item) => withCast(toSqlLiteral(item), condition.value_cast));
1722
+ return `${column} IN (${values.join(", ")})`;
1723
+ }
1724
+ default:
1725
+ return null;
1726
+ }
1727
+ }
1728
+ function buildTypedSelectQuery(input) {
1729
+ const whereClauses = [];
1730
+ for (const condition of input.conditions) {
1731
+ const clause = conditionToSqlClause(condition);
1732
+ if (!clause) return null;
1733
+ whereClauses.push(clause);
1734
+ }
1735
+ let limit = input.limit;
1736
+ let offset = input.offset;
1737
+ if (limit === void 0 && input.pageSize !== void 0) {
1738
+ limit = input.pageSize;
1739
+ }
1740
+ if (offset === void 0 && input.pageSize !== void 0 && input.currentPage !== void 0 && input.currentPage > 0) {
1741
+ offset = (input.currentPage - 1) * input.pageSize;
1742
+ }
1743
+ const sqlParts = [
1744
+ `SELECT ${buildSelectColumnsClause(input.columns)} FROM ${quoteQualifiedIdentifier(input.tableName)}`
1745
+ ];
1746
+ if (whereClauses.length > 0) {
1747
+ sqlParts.push(`WHERE ${whereClauses.join(" AND ")}`);
1748
+ }
1749
+ if (input.order?.field) {
1750
+ const direction = input.order.direction === "descending" ? "DESC" : "ASC";
1751
+ sqlParts.push(`ORDER BY ${quoteQualifiedIdentifier(input.order.field)} ${direction}`);
1752
+ }
1753
+ if (limit !== void 0) {
1754
+ sqlParts.push(`LIMIT ${Math.max(0, Math.trunc(limit))}`);
1755
+ }
1756
+ if (offset !== void 0) {
1757
+ sqlParts.push(`OFFSET ${Math.max(0, Math.trunc(offset))}`);
1758
+ }
1759
+ return `${sqlParts.join(" ")};`;
1760
+ }
1761
+ function createFilterMethods(state, addCondition, self) {
1762
+ return {
1763
+ eq(column, value) {
1764
+ const columnName = String(column);
1765
+ if (shouldUseUuidTextComparison(columnName, value)) {
1766
+ addCondition("eq", columnName, value, { columnCast: "text" });
1767
+ } else {
1768
+ addCondition("eq", columnName, value);
1769
+ }
1770
+ return self;
1771
+ },
1772
+ eqCast(column, value, cast) {
1773
+ addCondition("eq", String(column), value, { valueCast: cast });
1774
+ return self;
1775
+ },
1776
+ eqUuid(column, value) {
1777
+ addCondition("eq", String(column), value, { valueCast: "uuid" });
1778
+ return self;
1779
+ },
1780
+ match(filters) {
1781
+ Object.entries(filters).forEach(([column, value]) => {
1782
+ if (value === void 0) {
1783
+ return;
1784
+ }
1785
+ if (shouldUseUuidTextComparison(column, value)) {
1786
+ addCondition("eq", column, value, { columnCast: "text" });
1787
+ } else {
1788
+ addCondition("eq", column, value);
1789
+ }
1790
+ });
1791
+ return self;
1792
+ },
1793
+ range(from, to) {
1794
+ state.offset = from;
1795
+ state.limit = to - from + 1;
1796
+ return self;
1797
+ },
1798
+ limit(count) {
1799
+ state.limit = count;
1800
+ return self;
1801
+ },
1802
+ offset(count) {
1803
+ state.offset = count;
1804
+ return self;
1805
+ },
1806
+ currentPage(value) {
1807
+ state.currentPage = value;
1808
+ return self;
1809
+ },
1810
+ pageSize(value) {
1811
+ state.pageSize = value;
1812
+ return self;
1813
+ },
1814
+ totalPages(value) {
1815
+ state.totalPages = value;
1816
+ return self;
1817
+ },
1818
+ order(column, options) {
1819
+ state.order = {
1820
+ field: String(column),
1821
+ direction: options?.ascending === false ? "descending" : "ascending"
1822
+ };
1823
+ return self;
1824
+ },
1825
+ gt(column, value) {
1826
+ addCondition("gt", String(column), value);
1827
+ return self;
1828
+ },
1829
+ gte(column, value) {
1830
+ addCondition("gte", String(column), value);
1831
+ return self;
1832
+ },
1833
+ lt(column, value) {
1834
+ addCondition("lt", String(column), value);
1835
+ return self;
1836
+ },
1837
+ lte(column, value) {
1838
+ addCondition("lte", String(column), value);
1839
+ return self;
1840
+ },
1841
+ neq(column, value) {
1842
+ addCondition("neq", String(column), value);
1843
+ return self;
1844
+ },
1845
+ like(column, value) {
1846
+ addCondition("like", String(column), value);
1847
+ return self;
1848
+ },
1849
+ ilike(column, value) {
1850
+ addCondition("ilike", String(column), value);
1851
+ return self;
1852
+ },
1853
+ is(column, value) {
1854
+ addCondition("is", String(column), value);
1855
+ return self;
1856
+ },
1857
+ in(column, values) {
1858
+ addCondition("in", String(column), values);
1859
+ return self;
1860
+ },
1861
+ contains(column, values) {
1862
+ addCondition("contains", String(column), values);
1863
+ return self;
1864
+ },
1865
+ containedBy(column, values) {
1866
+ addCondition("containedBy", String(column), values);
1867
+ return self;
1868
+ },
1869
+ not(columnOrExpression, operator, value) {
1870
+ const expression = String(columnOrExpression);
1871
+ if (operator != null && value !== void 0) {
1872
+ addCondition("not", void 0, `${expression}.${operator}.${stringifyFilterValue(value)}`);
1873
+ } else {
1874
+ addCondition("not", void 0, expression);
1875
+ }
1876
+ return self;
1877
+ },
1878
+ or(expression) {
1879
+ addCondition("or", void 0, expression);
1880
+ return self;
1881
+ }
1882
+ };
1883
+ }
1884
+ function toRpcSelect(columns) {
1885
+ if (!columns) return void 0;
1886
+ return Array.isArray(columns) ? columns.join(",") : columns;
1887
+ }
1888
+ function createRpcFilterMethods(filters, self) {
1889
+ const addFilter = (operator, column, value) => {
1890
+ filters.push({ column, operator, value });
1891
+ };
1892
+ return {
1893
+ eq(column, value) {
1894
+ addFilter("eq", column, value);
1895
+ return self;
1896
+ },
1897
+ neq(column, value) {
1898
+ addFilter("neq", column, value);
1899
+ return self;
1900
+ },
1901
+ gt(column, value) {
1902
+ addFilter("gt", column, value);
1903
+ return self;
1904
+ },
1905
+ gte(column, value) {
1906
+ addFilter("gte", column, value);
1907
+ return self;
1908
+ },
1909
+ lt(column, value) {
1910
+ addFilter("lt", column, value);
1911
+ return self;
1912
+ },
1913
+ lte(column, value) {
1914
+ addFilter("lte", column, value);
1915
+ return self;
1916
+ },
1917
+ like(column, value) {
1918
+ addFilter("like", column, value);
1919
+ return self;
1920
+ },
1921
+ ilike(column, value) {
1922
+ addFilter("ilike", column, value);
1923
+ return self;
1924
+ },
1925
+ is(column, value) {
1926
+ addFilter("is", column, value);
1927
+ return self;
1928
+ },
1929
+ in(column, values) {
1930
+ addFilter("in", column, values);
1931
+ return self;
1932
+ }
1933
+ };
1934
+ }
1935
+ function createRpcBuilder(functionName, args, baseOptions, client) {
1936
+ const state = {
1937
+ filters: []
1938
+ };
1939
+ let selectedColumns;
1940
+ let selectedOptions;
1941
+ let promise = null;
1942
+ const executeRpc = async (columns, options) => {
1943
+ const mergedOptions = mergeOptions(baseOptions, options);
1944
+ const payload = {
1945
+ function: functionName,
1946
+ args,
1947
+ schema: mergedOptions?.schema,
1948
+ select: toRpcSelect(columns),
1949
+ filters: state.filters.length ? [...state.filters] : void 0,
1950
+ count: mergedOptions?.count,
1951
+ head: mergedOptions?.head,
1952
+ limit: state.limit,
1953
+ offset: state.offset,
1954
+ order: state.order
1955
+ };
1956
+ const response = await client.rpcGateway(payload, mergedOptions);
1957
+ return formatResult(response);
1958
+ };
1959
+ const run = (columns, options) => {
1960
+ const payloadColumns = columns ?? selectedColumns;
1961
+ const payloadOptions = options ?? selectedOptions;
1962
+ if (!promise) {
1963
+ promise = executeRpc(payloadColumns, payloadOptions);
1964
+ }
1965
+ return promise;
1966
+ };
1967
+ const builder = {};
1968
+ const filterMethods = createRpcFilterMethods(state.filters, builder);
1969
+ Object.assign(builder, filterMethods, {
1970
+ select(columns = selectedColumns, options) {
1971
+ selectedColumns = columns;
1972
+ selectedOptions = options ?? selectedOptions;
1973
+ return run(columns, options);
1974
+ },
1975
+ async single(columns, options) {
1976
+ const result = await run(columns, options);
1977
+ return toSingleResult(result);
1978
+ },
1979
+ maybeSingle(columns, options) {
1980
+ return builder.single(columns, options);
1981
+ },
1982
+ order(column, options) {
1983
+ state.order = { column, ascending: options?.ascending ?? true };
1984
+ return builder;
1985
+ },
1986
+ limit(count) {
1987
+ state.limit = count;
1988
+ return builder;
1989
+ },
1990
+ offset(count) {
1991
+ state.offset = count;
1992
+ return builder;
1993
+ },
1994
+ range(from, to) {
1995
+ state.offset = from;
1996
+ state.limit = to - from + 1;
1997
+ return builder;
1998
+ },
1999
+ then(onfulfilled, onrejected) {
2000
+ return run(selectedColumns, selectedOptions).then(onfulfilled, onrejected);
2001
+ },
2002
+ catch(onrejected) {
2003
+ return run(selectedColumns, selectedOptions).catch(onrejected);
2004
+ },
2005
+ finally(onfinally) {
2006
+ return run(selectedColumns, selectedOptions).finally(onfinally);
2007
+ }
2008
+ });
2009
+ return builder;
2010
+ }
2011
+ function createTableBuilder(tableName, client) {
2012
+ const state = {
2013
+ conditions: []
2014
+ };
2015
+ const addCondition = (operator, column, value, hints) => {
2016
+ const condition = { operator };
2017
+ if (column) {
2018
+ condition.column = column;
2019
+ if (operator === "eq") {
2020
+ condition.eq_column = column;
2021
+ }
2022
+ }
2023
+ if (value !== void 0) {
2024
+ condition.value = value;
2025
+ if (operator === "eq") {
2026
+ condition.eq_value = value;
2027
+ }
2028
+ }
2029
+ if (hints?.valueCast) {
2030
+ condition.value_cast = hints.valueCast;
2031
+ if (operator === "eq") {
2032
+ condition.eq_value_cast = hints.valueCast;
2033
+ }
2034
+ }
2035
+ if (hints?.columnCast) {
2036
+ condition.column_cast = hints.columnCast;
2037
+ if (operator === "eq") {
2038
+ condition.eq_column_cast = hints.columnCast;
2039
+ }
2040
+ }
2041
+ state.conditions.push(condition);
2042
+ };
2043
+ const builder = {};
2044
+ const filterMethods = createFilterMethods(
2045
+ state,
2046
+ addCondition,
2047
+ builder
2048
+ );
2049
+ const runSelect = async (columns = DEFAULT_COLUMNS, options) => {
2050
+ const resolvedTableName = resolveTableNameForCall(tableName, options?.schema);
2051
+ const conditions = state.conditions.length ? state.conditions.map((condition) => ({ ...condition })) : void 0;
2052
+ const hasTypedEqualityComparison = conditions?.some(
2053
+ (condition) => condition.operator === "eq" && (condition.value_cast !== void 0 || condition.column_cast !== void 0)
2054
+ ) ?? false;
2055
+ if (hasTypedEqualityComparison && !options?.head && !options?.count && conditions) {
2056
+ const query = buildTypedSelectQuery({
2057
+ tableName: resolvedTableName,
2058
+ columns,
2059
+ conditions,
2060
+ limit: state.limit,
2061
+ offset: state.offset,
2062
+ currentPage: state.currentPage,
2063
+ pageSize: state.pageSize,
2064
+ order: state.order
2065
+ });
2066
+ if (query) {
2067
+ const queryResponse = await client.queryGateway({ query }, options);
2068
+ return formatResult(queryResponse);
2069
+ }
2070
+ }
2071
+ const payload = {
2072
+ table_name: resolvedTableName,
2073
+ columns,
2074
+ conditions,
2075
+ limit: state.limit,
2076
+ offset: state.offset,
2077
+ current_page: state.currentPage,
2078
+ page_size: state.pageSize,
2079
+ total_pages: state.totalPages,
2080
+ sort_by: state.order,
2081
+ strip_nulls: options?.stripNulls ?? true,
2082
+ count: options?.count,
2083
+ head: options?.head
2084
+ };
2085
+ const response = await client.fetchGateway(payload, options);
2086
+ return formatResult(response);
2087
+ };
2088
+ const createSelectChain = (columns, options) => {
2089
+ const chain = {};
2090
+ const filterMethods2 = createFilterMethods(state, addCondition, chain);
2091
+ Object.assign(chain, filterMethods2, {
2092
+ async single(cols, opts) {
2093
+ const r = await runSelect(cols ?? columns, opts ?? options);
2094
+ return toSingleResult(r);
2095
+ },
2096
+ maybeSingle(cols, opts) {
2097
+ return chain.single(cols, opts);
2098
+ },
2099
+ then(onfulfilled, onrejected) {
2100
+ return runSelect(columns, options).then(onfulfilled, onrejected);
2101
+ },
2102
+ catch(onrejected) {
2103
+ return runSelect(columns, options).catch(onrejected);
2104
+ },
2105
+ finally(onfinally) {
2106
+ return runSelect(columns, options).finally(onfinally);
2107
+ }
2108
+ });
2109
+ return chain;
2110
+ };
2111
+ Object.assign(builder, filterMethods, {
2112
+ reset() {
2113
+ state.conditions = [];
1044
2114
  state.limit = void 0;
1045
2115
  state.offset = void 0;
1046
2116
  state.order = void 0;
@@ -1056,9 +2126,10 @@ function createTableBuilder(tableName, client) {
1056
2126
  if (Array.isArray(values)) {
1057
2127
  const executeInsertMany = async (columns, selectOptions) => {
1058
2128
  const mergedOptions = mergeOptions(options, selectOptions);
2129
+ const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
1059
2130
  const payload = {
1060
- table_name: tableName,
1061
- insert_body: values
2131
+ table_name: resolvedTableName,
2132
+ insert_body: asAthenaJsonObjectArray(values)
1062
2133
  };
1063
2134
  if (columns) payload.columns = columns;
1064
2135
  if (mergedOptions?.count) payload.count = mergedOptions.count;
@@ -1073,9 +2144,10 @@ function createTableBuilder(tableName, client) {
1073
2144
  }
1074
2145
  const executeInsertOne = async (columns, selectOptions) => {
1075
2146
  const mergedOptions = mergeOptions(options, selectOptions);
2147
+ const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
1076
2148
  const payload = {
1077
- table_name: tableName,
1078
- insert_body: values
2149
+ table_name: resolvedTableName,
2150
+ insert_body: asAthenaJsonObject(values)
1079
2151
  };
1080
2152
  if (columns) payload.columns = columns;
1081
2153
  if (mergedOptions?.count) payload.count = mergedOptions.count;
@@ -1092,10 +2164,11 @@ function createTableBuilder(tableName, client) {
1092
2164
  if (Array.isArray(values)) {
1093
2165
  const executeUpsertMany = async (columns, selectOptions) => {
1094
2166
  const mergedOptions = mergeOptions(options, selectOptions);
2167
+ const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
1095
2168
  const payload = {
1096
- table_name: tableName,
1097
- insert_body: values,
1098
- update_body: options?.updateBody ? options.updateBody : void 0
2169
+ table_name: resolvedTableName,
2170
+ insert_body: asAthenaJsonObjectArray(values),
2171
+ update_body: options?.updateBody ? asAthenaJsonObject(options.updateBody) : void 0
1099
2172
  };
1100
2173
  if (columns) payload.columns = columns;
1101
2174
  if (options?.onConflict) payload.on_conflict = options.onConflict;
@@ -1111,10 +2184,11 @@ function createTableBuilder(tableName, client) {
1111
2184
  }
1112
2185
  const executeUpsertOne = async (columns, selectOptions) => {
1113
2186
  const mergedOptions = mergeOptions(options, selectOptions);
2187
+ const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
1114
2188
  const payload = {
1115
- table_name: tableName,
1116
- insert_body: values,
1117
- update_body: options?.updateBody ? options.updateBody : void 0
2189
+ table_name: resolvedTableName,
2190
+ insert_body: asAthenaJsonObject(values),
2191
+ update_body: options?.updateBody ? asAthenaJsonObject(options.updateBody) : void 0
1118
2192
  };
1119
2193
  if (columns) payload.columns = columns;
1120
2194
  if (options?.onConflict) payload.on_conflict = options.onConflict;
@@ -1132,9 +2206,10 @@ function createTableBuilder(tableName, client) {
1132
2206
  const executeUpdate = async (columns, selectOptions) => {
1133
2207
  const filters = state.conditions.length ? [...state.conditions] : void 0;
1134
2208
  const mergedOptions = mergeOptions(options, selectOptions);
2209
+ const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
1135
2210
  const payload = {
1136
- table_name: tableName,
1137
- set: values,
2211
+ table_name: resolvedTableName,
2212
+ set: asAthenaJsonObject(values),
1138
2213
  conditions: filters,
1139
2214
  strip_nulls: mergedOptions?.stripNulls ?? true
1140
2215
  };
@@ -1160,8 +2235,9 @@ function createTableBuilder(tableName, client) {
1160
2235
  }
1161
2236
  const executeDelete = async (columns, selectOptions) => {
1162
2237
  const mergedOptions = mergeOptions(options, selectOptions);
2238
+ const resolvedTableName = resolveTableNameForCall(tableName, mergedOptions?.schema);
1163
2239
  const payload = {
1164
- table_name: tableName,
2240
+ table_name: resolvedTableName,
1165
2241
  resource_id: resourceId,
1166
2242
  conditions: filters
1167
2243
  };
@@ -1203,6 +2279,7 @@ function createClientFromConfig(config) {
1203
2279
  backend: config.backend,
1204
2280
  headers: config.headers
1205
2281
  });
2282
+ const auth = createAuthClient(config.auth);
1206
2283
  return {
1207
2284
  from(table) {
1208
2285
  return createTableBuilder(table, gateway);
@@ -1219,7 +2296,8 @@ function createClientFromConfig(config) {
1219
2296
  gateway
1220
2297
  );
1221
2298
  },
1222
- query: createQueryBuilder(gateway)
2299
+ query: createQueryBuilder(gateway),
2300
+ auth: auth.auth
1223
2301
  };
1224
2302
  }
1225
2303
  var DEFAULT_BACKEND = { type: "athena" };
@@ -1293,7 +2371,11 @@ function createClient(url, apiKey, options) {
1293
2371
  const b = AthenaClient.builder().url(url).key(apiKey).backend(toBackendConfig(options?.backend));
1294
2372
  if (options?.client) b.client(options.client);
1295
2373
  if (options?.headers && Object.keys(options.headers).length > 0) b.headers(options.headers);
1296
- return b.build();
2374
+ const client = b.build();
2375
+ if (options?.auth) {
2376
+ client.auth = createAuthClient(options.auth).auth;
2377
+ }
2378
+ return client;
1297
2379
  }
1298
2380
 
1299
2381
  // src/gateway/types.ts
@@ -1333,6 +2415,17 @@ var AthenaErrorCategory = {
1333
2415
  Database: "database",
1334
2416
  Unknown: "unknown"
1335
2417
  };
2418
+ function parseBooleanFlag(rawValue, fallback) {
2419
+ if (!rawValue) return fallback;
2420
+ const normalized = rawValue.trim().toLowerCase();
2421
+ if (normalized === "1" || normalized === "true" || normalized === "yes" || normalized === "on") {
2422
+ return true;
2423
+ }
2424
+ if (normalized === "0" || normalized === "false" || normalized === "no" || normalized === "off") {
2425
+ return false;
2426
+ }
2427
+ return fallback;
2428
+ }
1336
2429
  var AthenaError = class extends Error {
1337
2430
  code;
1338
2431
  kind;
@@ -1355,7 +2448,7 @@ var AthenaError = class extends Error {
1355
2448
  this.raw = input.raw;
1356
2449
  }
1357
2450
  };
1358
- function isRecord2(value) {
2451
+ function isRecord3(value) {
1359
2452
  return Boolean(value) && typeof value === "object" && !Array.isArray(value);
1360
2453
  }
1361
2454
  function safeStringify(value) {
@@ -1372,7 +2465,7 @@ function contextHint(context) {
1372
2465
  return `Identity: ${identity}`;
1373
2466
  }
1374
2467
  function isAthenaResultLike(value) {
1375
- return isRecord2(value) && "status" in value && "error" in value && "data" in value && typeof value.status === "number";
2468
+ return isRecord3(value) && "status" in value && "error" in value && "data" in value && typeof value.status === "number";
1376
2469
  }
1377
2470
  function operationFromDetails(details) {
1378
2471
  if (!details?.endpoint) return void 0;
@@ -1538,7 +2631,7 @@ function normalizeAthenaError(resultOrError, context) {
1538
2631
  };
1539
2632
  }
1540
2633
  if (resultOrError instanceof Error) {
1541
- const maybeStatus = isRecord2(resultOrError) && typeof resultOrError.status === "number" ? resultOrError.status : void 0;
2634
+ const maybeStatus = isRecord3(resultOrError) && typeof resultOrError.status === "number" ? resultOrError.status : void 0;
1542
2635
  const kind2 = classifyKind(maybeStatus, void 0, resultOrError.message);
1543
2636
  return {
1544
2637
  kind: kind2,
@@ -2274,6 +3367,67 @@ function createPostgresIntrospectionProvider(options) {
2274
3367
  return new PostgresIntrospectionProvider(options);
2275
3368
  }
2276
3369
 
3370
+ // src/schema/model-form.ts
3371
+ function resolveNullishValue(mode) {
3372
+ if (mode === "undefined") return void 0;
3373
+ if (mode === "null") return null;
3374
+ return "";
3375
+ }
3376
+ function isRecord4(value) {
3377
+ return Boolean(value) && typeof value === "object" && !Array.isArray(value);
3378
+ }
3379
+ function isNullableColumn(model, key) {
3380
+ const nullable = model.meta.nullable;
3381
+ return nullable?.[key] === true;
3382
+ }
3383
+ function toModelFormDefaults(model, values, options) {
3384
+ const source = values;
3385
+ if (!isRecord4(source)) {
3386
+ return {};
3387
+ }
3388
+ const mode = options?.nullishMode ?? "empty-string";
3389
+ const nullishValue = resolveNullishValue(mode);
3390
+ const result = {};
3391
+ for (const [key, value] of Object.entries(source)) {
3392
+ if (value === null && isNullableColumn(model, key)) {
3393
+ result[key] = nullishValue;
3394
+ continue;
3395
+ }
3396
+ result[key] = value;
3397
+ }
3398
+ return result;
3399
+ }
3400
+ function toModelPayload(model, formValues, options) {
3401
+ const emptyStringAsNull = options?.emptyStringAsNull ?? true;
3402
+ const stripUndefined = options?.stripUndefined ?? true;
3403
+ const result = {};
3404
+ for (const [key, rawValue] of Object.entries(formValues)) {
3405
+ if (rawValue === void 0 && stripUndefined) {
3406
+ continue;
3407
+ }
3408
+ if (emptyStringAsNull && rawValue === "" && isNullableColumn(model, key)) {
3409
+ result[key] = null;
3410
+ continue;
3411
+ }
3412
+ result[key] = rawValue;
3413
+ }
3414
+ return result;
3415
+ }
3416
+ function createModelFormAdapter(model) {
3417
+ return {
3418
+ model,
3419
+ toDefaults(values, options) {
3420
+ return toModelFormDefaults(model, values, options);
3421
+ },
3422
+ toInsert(values, options) {
3423
+ return toModelPayload(model, values, options);
3424
+ },
3425
+ toUpdate(values, options) {
3426
+ return toModelPayload(model, values, options);
3427
+ }
3428
+ };
3429
+ }
3430
+
2277
3431
  // src/generator/schema-selection.ts
2278
3432
  var DEFAULT_POSTGRES_SCHEMAS = ["public"];
2279
3433
  function collectSchemaNames(input) {
@@ -2333,6 +3487,39 @@ var DEFAULT_EXPERIMENTAL_FLAGS = {
2333
3487
  postgresGatewayIntrospection: false,
2334
3488
  scyllaProviderContracts: true
2335
3489
  };
3490
+ function normalizeBooleanFlag(rawValue, fallback) {
3491
+ if (typeof rawValue === "boolean") {
3492
+ return rawValue;
3493
+ }
3494
+ if (typeof rawValue === "string") {
3495
+ return parseBooleanFlag(rawValue, fallback);
3496
+ }
3497
+ return fallback;
3498
+ }
3499
+ function normalizeFeatureFlags(input) {
3500
+ return {
3501
+ emitRelations: normalizeBooleanFlag(
3502
+ input?.emitRelations,
3503
+ DEFAULT_FEATURES.emitRelations
3504
+ ),
3505
+ emitRegistry: normalizeBooleanFlag(
3506
+ input?.emitRegistry,
3507
+ DEFAULT_FEATURES.emitRegistry
3508
+ )
3509
+ };
3510
+ }
3511
+ function normalizeExperimentalFlags(input) {
3512
+ return {
3513
+ postgresGatewayIntrospection: normalizeBooleanFlag(
3514
+ input?.postgresGatewayIntrospection,
3515
+ DEFAULT_EXPERIMENTAL_FLAGS.postgresGatewayIntrospection
3516
+ ),
3517
+ scyllaProviderContracts: normalizeBooleanFlag(
3518
+ input?.scyllaProviderContracts,
3519
+ DEFAULT_EXPERIMENTAL_FLAGS.scyllaProviderContracts
3520
+ )
3521
+ };
3522
+ }
2336
3523
  function normalizeOutputConfig(output) {
2337
3524
  return {
2338
3525
  targets: {
@@ -2368,14 +3555,8 @@ function normalizeGeneratorConfig(input) {
2368
3555
  ...DEFAULT_NAMING,
2369
3556
  ...input.naming ?? {}
2370
3557
  },
2371
- features: {
2372
- ...DEFAULT_FEATURES,
2373
- ...input.features ?? {}
2374
- },
2375
- experimental: {
2376
- ...DEFAULT_EXPERIMENTAL_FLAGS,
2377
- ...input.experimental ?? {}
2378
- }
3558
+ features: normalizeFeatureFlags(input.features),
3559
+ experimental: normalizeExperimentalFlags(input.experimental)
2379
3560
  };
2380
3561
  }
2381
3562
  function defineGeneratorConfig(config) {
@@ -2985,633 +4166,142 @@ var ArtifactComposer = class {
2985
4166
  files
2986
4167
  };
2987
4168
  }
2988
- };
2989
- function generateArtifactsFromSnapshot(snapshot, config) {
2990
- const normalizedConfig = "naming" in config && "features" in config && "experimental" in config ? config : normalizeGeneratorConfig(config);
2991
- return new ArtifactComposer(snapshot, normalizedConfig).compose();
2992
- }
2993
-
2994
- // src/generator/providers.ts
2995
- var AthenaGatewayCatalogClient = class {
2996
- constructor(client) {
2997
- this.client = client;
2998
- }
2999
- async queryRows(query) {
3000
- const result = await this.client.query(query);
3001
- if (result.error || result.status < 200 || result.status >= 300) {
3002
- throw new Error(result.error ?? `Gateway query failed with status ${result.status}`);
3003
- }
3004
- return result.data ?? [];
3005
- }
3006
- async queryColumns(query) {
3007
- return this.queryRows(query);
3008
- }
3009
- async queryEnums(query) {
3010
- const rows = await this.queryRows(query);
3011
- const enumMap = /* @__PURE__ */ new Map();
3012
- for (const row of rows) {
3013
- const existing = enumMap.get(row.type_oid) ?? [];
3014
- existing.push(row.enum_label);
3015
- enumMap.set(row.type_oid, existing);
3016
- }
3017
- return enumMap;
3018
- }
3019
- async queryPrimaryKeys(query) {
3020
- return this.queryRows(query);
3021
- }
3022
- async queryForeignKeys(query) {
3023
- return this.queryRows(query);
3024
- }
3025
- };
3026
- var AthenaGatewayPostgresIntrospectionProvider = class {
3027
- constructor(config) {
3028
- this.config = config;
3029
- this.client = createClient(this.config.gatewayUrl, this.config.apiKey, {
3030
- backend: {
3031
- type: this.config.backend ?? "postgresql"
3032
- }
3033
- });
3034
- this.schemas = normalizeSchemaSelection(this.config.schemas);
3035
- }
3036
- backend = "postgresql";
3037
- client;
3038
- schemas;
3039
- async inspect(options) {
3040
- const schemas = options?.schemas && options.schemas.length > 0 ? normalizeSchemaSelection(options.schemas) : this.schemas;
3041
- const catalogClient = new AthenaGatewayCatalogClient(this.client);
3042
- const queries = buildGatewayCatalogQueries(schemas);
3043
- const [columnRows, enumMap, primaryKeyRows, foreignKeyRows] = await Promise.all([
3044
- catalogClient.queryColumns(queries.columns),
3045
- catalogClient.queryEnums(queries.enums),
3046
- catalogClient.queryPrimaryKeys(queries.primaryKeys),
3047
- catalogClient.queryForeignKeys(queries.foreignKeys)
3048
- ]);
3049
- const assembler = new PostgresCatalogSnapshotAssembler();
3050
- assembler.addColumnRows(columnRows, enumMap);
3051
- assembler.addPrimaryKeyRows(primaryKeyRows);
3052
- assembler.addForeignKeyRows(foreignKeyRows);
3053
- assembler.addManyToManyRows(foreignKeyRows);
3054
- return {
3055
- backend: "postgresql",
3056
- database: this.config.database,
3057
- generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
3058
- schemas: assembler.toSchemas()
3059
- };
3060
- }
3061
- };
3062
- var ScyllaIntrospectionProvider = class {
3063
- constructor(config) {
3064
- this.config = config;
3065
- }
3066
- backend = "scylladb";
3067
- async inspect() {
3068
- throw new Error(
3069
- `Scylla introspection provider is not implemented yet for keyspace ${this.config.keyspace}.`
3070
- );
3071
- }
3072
- };
3073
- function createPostgresProvider(config) {
3074
- return createPostgresIntrospectionProvider({
3075
- connectionString: config.connectionString,
3076
- database: config.database,
3077
- schemas: normalizeSchemaSelection(config.schemas)
3078
- });
3079
- }
3080
- function resolveGeneratorProvider(providerConfig, experimentalFlags) {
3081
- if (providerConfig.kind === "postgres" && providerConfig.mode === "direct") {
3082
- return createPostgresProvider(providerConfig);
3083
- }
3084
- if (providerConfig.kind === "postgres" && providerConfig.mode === "gateway") {
3085
- return new AthenaGatewayPostgresIntrospectionProvider(providerConfig);
3086
- }
3087
- if (providerConfig.kind === "scylla") {
3088
- if (!experimentalFlags.scyllaProviderContracts) {
3089
- throw new Error(
3090
- "Scylla provider contracts are disabled. Set experimental.scyllaProviderContracts=true to enable placeholders."
3091
- );
3092
- }
3093
- return new ScyllaIntrospectionProvider(providerConfig);
3094
- }
3095
- throw new Error(`Unsupported generator provider kind: ${providerConfig.kind ?? "unknown"}`);
3096
- }
3097
- async function writeArtifacts(files, cwd) {
3098
- const writtenFiles = [];
3099
- for (const file of files) {
3100
- const absolutePath = path.resolve(cwd, file.path);
3101
- await promises.mkdir(path.dirname(absolutePath), { recursive: true });
3102
- await promises.writeFile(absolutePath, file.content, "utf8");
3103
- writtenFiles.push(file.path);
3104
- }
3105
- return writtenFiles;
3106
- }
3107
- async function runSchemaGenerator(options = {}) {
3108
- const cwd = options.cwd ?? process.cwd();
3109
- const configOptions = {
3110
- cwd,
3111
- configPath: options.configPath
3112
- };
3113
- const { configPath, config } = await loadGeneratorConfig(configOptions);
3114
- const provider = options.provider ?? resolveGeneratorProvider(config.provider, config.experimental);
3115
- const snapshot = await provider.inspect({
3116
- schemas: resolveProviderSchemas(config.provider)
3117
- });
3118
- const generated = generateArtifactsFromSnapshot(snapshot, config);
3119
- const writtenFiles = options.dryRun ? [] : await writeArtifacts(generated.files, cwd);
3120
- return {
3121
- ...generated,
3122
- configPath,
3123
- writtenFiles
3124
- };
3125
- }
3126
-
3127
- // src/auth/client.ts
3128
- var DEFAULT_AUTH_BASE_URL = "http://localhost:3001/api/auth";
3129
- var FALLBACK_SDK_VERSION2 = "1.0.0";
3130
- var SDK_NAME2 = "xylex-group/athena-auth";
3131
- var SDK_VERSION2 = typeof process !== "undefined" && process?.env?.npm_package_version ? process.env.npm_package_version : FALLBACK_SDK_VERSION2;
3132
- var SDK_HEADER_VALUE2 = `${SDK_NAME2} ${SDK_VERSION2}`;
3133
- function normalizeBaseUrl(baseUrl) {
3134
- return (baseUrl ?? DEFAULT_AUTH_BASE_URL).replace(/\/$/, "");
3135
- }
3136
- function isRecord3(value) {
3137
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
3138
- }
3139
- function normalizeHeaderValue2(value) {
3140
- return value ? value : void 0;
3141
- }
3142
- function parseResponseBody2(rawText, contentType) {
3143
- if (!rawText) {
3144
- return { parsed: null, parseFailed: false };
3145
- }
3146
- const contentTypeSuggestsJson = contentType?.toLowerCase().includes("application/json") ?? false;
3147
- const looksJson = contentTypeSuggestsJson || rawText.startsWith("{") || rawText.startsWith("[");
3148
- if (!looksJson) {
3149
- return { parsed: rawText, parseFailed: false };
3150
- }
3151
- try {
3152
- return { parsed: JSON.parse(rawText), parseFailed: false };
3153
- } catch {
3154
- return { parsed: rawText, parseFailed: true };
3155
- }
3156
- }
3157
- function resolveRequestId2(headers) {
3158
- return headers.get("x-request-id") ?? headers.get("x-correlation-id") ?? headers.get("x-athena-request-id") ?? void 0;
3159
- }
3160
- function resolveErrorMessage2(payload, fallback) {
3161
- if (isRecord3(payload)) {
3162
- const messageCandidates = [payload.error, payload.message, payload.details];
3163
- for (const candidate of messageCandidates) {
3164
- if (typeof candidate === "string" && candidate.trim().length > 0) {
3165
- return candidate.trim();
3166
- }
3167
- }
3168
- }
3169
- if (typeof payload === "string" && payload.trim().length > 0) {
3170
- return payload.trim();
3171
- }
3172
- return fallback;
3173
- }
3174
- function toErrorDetails(input) {
3175
- return {
3176
- code: input.code,
3177
- message: input.message,
3178
- status: input.status,
3179
- endpoint: input.endpoint,
3180
- method: input.method,
3181
- requestId: input.requestId,
3182
- hint: input.hint,
3183
- cause: input.cause
3184
- };
3185
- }
3186
- function mergeCallOptions(base, override) {
3187
- if (!base && !override) return void 0;
3188
- return {
3189
- ...base,
3190
- ...override,
3191
- headers: {
3192
- ...base?.headers ?? {},
3193
- ...override?.headers ?? {}
3194
- }
3195
- };
3196
- }
3197
- function extractFetchOptions(input) {
3198
- if (!input) {
3199
- return {
3200
- payload: void 0,
3201
- fetchOptions: void 0
3202
- };
3203
- }
3204
- const { fetchOptions, ...rest } = input;
3205
- const hasPayloadKeys = Object.keys(rest).length > 0;
3206
- return {
3207
- payload: hasPayloadKeys ? rest : void 0,
3208
- fetchOptions
3209
- };
4169
+ };
4170
+ function generateArtifactsFromSnapshot(snapshot, config) {
4171
+ const normalizedConfig = "naming" in config && "features" in config && "experimental" in config ? config : normalizeGeneratorConfig(config);
4172
+ return new ArtifactComposer(snapshot, normalizedConfig).compose();
3210
4173
  }
3211
- function buildHeaders2(config, options) {
3212
- const headers = {
3213
- "Content-Type": "application/json",
3214
- "X-Athena-Sdk": SDK_HEADER_VALUE2
3215
- };
3216
- const apiKey = options?.apiKey ?? config.apiKey;
3217
- if (apiKey) {
3218
- headers.apikey = apiKey;
3219
- headers["x-api-key"] = apiKey;
3220
- }
3221
- const bearerToken = options?.bearerToken ?? config.bearerToken;
3222
- if (bearerToken) {
3223
- headers.Authorization = `Bearer ${bearerToken}`;
4174
+
4175
+ // src/generator/providers.ts
4176
+ var AthenaGatewayCatalogClient = class {
4177
+ constructor(client) {
4178
+ this.client = client;
3224
4179
  }
3225
- const mergedExtraHeaders = {
3226
- ...config.headers ?? {},
3227
- ...options?.headers ?? {}
3228
- };
3229
- Object.entries(mergedExtraHeaders).forEach(([key, value]) => {
3230
- const normalized = normalizeHeaderValue2(value);
3231
- if (normalized) {
3232
- headers[key] = normalized;
4180
+ async queryRows(query) {
4181
+ const result = await this.client.query(query);
4182
+ if (result.error || result.status < 200 || result.status >= 300) {
4183
+ throw new Error(result.error ?? `Gateway query failed with status ${result.status}`);
3233
4184
  }
3234
- });
3235
- return headers;
3236
- }
3237
- function appendQueryParam(searchParams, key, value) {
3238
- if (value === void 0 || value === null) return;
3239
- if (Array.isArray(value)) {
3240
- value.forEach((item) => {
3241
- searchParams.append(key, String(item));
3242
- });
3243
- return;
4185
+ return result.data ?? [];
3244
4186
  }
3245
- searchParams.append(key, String(value));
3246
- }
3247
- function buildRequestUrl(baseUrl, endpoint, query) {
3248
- const url = `${baseUrl}${endpoint}`;
3249
- if (!query || Object.keys(query).length === 0) return url;
3250
- const searchParams = new URLSearchParams();
3251
- Object.entries(query).forEach(([key, value]) => appendQueryParam(searchParams, key, value));
3252
- const queryText = searchParams.toString();
3253
- return queryText ? `${url}?${queryText}` : url;
3254
- }
3255
- function inferDefaultMethod(endpoint) {
3256
- if (endpoint.startsWith("/reset-password/")) {
3257
- return "GET";
4187
+ async queryColumns(query) {
4188
+ return this.queryRows(query);
3258
4189
  }
3259
- switch (endpoint) {
3260
- case "/get-session":
3261
- case "/list-sessions":
3262
- case "/verify-email":
3263
- case "/delete-user/callback":
3264
- case "/list-accounts":
3265
- case "/ok":
3266
- case "/error":
3267
- return "GET";
3268
- default:
3269
- return "POST";
4190
+ async queryEnums(query) {
4191
+ const rows = await this.queryRows(query);
4192
+ const enumMap = /* @__PURE__ */ new Map();
4193
+ for (const row of rows) {
4194
+ const existing = enumMap.get(row.type_oid) ?? [];
4195
+ existing.push(row.enum_label);
4196
+ enumMap.set(row.type_oid, existing);
4197
+ }
4198
+ return enumMap;
3270
4199
  }
3271
- }
3272
- async function callAuthEndpoint(config, context, body, query, options) {
3273
- const baseUrl = normalizeBaseUrl(options?.baseUrl ?? config.baseUrl);
3274
- const url = buildRequestUrl(baseUrl, context.endpoint, query);
3275
- const headers = buildHeaders2(config, options);
3276
- const credentials = options?.credentials ?? config.credentials ?? "include";
3277
- const requestInit = {
3278
- method: context.method,
3279
- headers,
3280
- credentials,
3281
- signal: options?.signal
3282
- };
3283
- if (context.method !== "GET") {
3284
- requestInit.body = JSON.stringify(body ?? {});
4200
+ async queryPrimaryKeys(query) {
4201
+ return this.queryRows(query);
3285
4202
  }
3286
- const fetcher = config.fetch ?? globalThis.fetch;
3287
- if (!fetcher) {
3288
- const details = toErrorDetails({
3289
- code: "UNKNOWN_ERROR",
3290
- message: "No fetch implementation available for auth client",
3291
- status: 0,
3292
- endpoint: context.endpoint,
3293
- method: context.method,
3294
- hint: "Use Node 18+ or provide `fetch` in createAuthClient({ fetch })"
4203
+ async queryForeignKeys(query) {
4204
+ return this.queryRows(query);
4205
+ }
4206
+ };
4207
+ var AthenaGatewayPostgresIntrospectionProvider = class {
4208
+ constructor(config) {
4209
+ this.config = config;
4210
+ this.client = createClient(this.config.gatewayUrl, this.config.apiKey, {
4211
+ backend: {
4212
+ type: this.config.backend ?? "postgresql"
4213
+ }
3295
4214
  });
4215
+ this.schemas = normalizeSchemaSelection(this.config.schemas);
4216
+ }
4217
+ backend = "postgresql";
4218
+ client;
4219
+ schemas;
4220
+ async inspect(options) {
4221
+ const schemas = options?.schemas && options.schemas.length > 0 ? normalizeSchemaSelection(options.schemas) : this.schemas;
4222
+ const catalogClient = new AthenaGatewayCatalogClient(this.client);
4223
+ const queries = buildGatewayCatalogQueries(schemas);
4224
+ const [columnRows, enumMap, primaryKeyRows, foreignKeyRows] = await Promise.all([
4225
+ catalogClient.queryColumns(queries.columns),
4226
+ catalogClient.queryEnums(queries.enums),
4227
+ catalogClient.queryPrimaryKeys(queries.primaryKeys),
4228
+ catalogClient.queryForeignKeys(queries.foreignKeys)
4229
+ ]);
4230
+ const assembler = new PostgresCatalogSnapshotAssembler();
4231
+ assembler.addColumnRows(columnRows, enumMap);
4232
+ assembler.addPrimaryKeyRows(primaryKeyRows);
4233
+ assembler.addForeignKeyRows(foreignKeyRows);
4234
+ assembler.addManyToManyRows(foreignKeyRows);
3296
4235
  return {
3297
- ok: false,
3298
- status: 0,
3299
- data: null,
3300
- error: details.message,
3301
- errorDetails: details,
3302
- raw: null
4236
+ backend: "postgresql",
4237
+ database: this.config.database,
4238
+ generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
4239
+ schemas: assembler.toSchemas()
3303
4240
  };
3304
4241
  }
3305
- try {
3306
- const response = await fetcher(url, requestInit);
3307
- const rawText = await response.text();
3308
- const requestId = resolveRequestId2(response.headers);
3309
- const parsedBody = parseResponseBody2(rawText ?? "", response.headers.get("content-type"));
3310
- if (parsedBody.parseFailed) {
3311
- const details = toErrorDetails({
3312
- code: "INVALID_JSON",
3313
- message: "Auth server returned malformed JSON",
3314
- status: response.status,
3315
- endpoint: context.endpoint,
3316
- method: context.method,
3317
- requestId,
3318
- hint: "Verify the auth endpoint response body is valid JSON.",
3319
- cause: rawText.slice(0, 300)
3320
- });
3321
- return {
3322
- ok: false,
3323
- status: response.status,
3324
- data: null,
3325
- error: details.message,
3326
- errorDetails: details,
3327
- raw: parsedBody.parsed
3328
- };
3329
- }
3330
- const parsed = parsedBody.parsed;
3331
- if (!response.ok) {
3332
- const details = toErrorDetails({
3333
- code: "HTTP_ERROR",
3334
- message: resolveErrorMessage2(
3335
- parsed,
3336
- `Auth endpoint ${context.method} ${context.endpoint} failed with status ${response.status}`
3337
- ),
3338
- status: response.status,
3339
- endpoint: context.endpoint,
3340
- method: context.method,
3341
- requestId
3342
- });
3343
- return {
3344
- ok: false,
3345
- status: response.status,
3346
- data: null,
3347
- error: details.message,
3348
- errorDetails: details,
3349
- raw: parsed
3350
- };
4242
+ };
4243
+ var ScyllaIntrospectionProvider = class {
4244
+ constructor(config) {
4245
+ this.config = config;
4246
+ }
4247
+ backend = "scylladb";
4248
+ async inspect() {
4249
+ throw new Error(
4250
+ `Scylla introspection provider is not implemented yet for keyspace ${this.config.keyspace}.`
4251
+ );
4252
+ }
4253
+ };
4254
+ function createPostgresProvider(config) {
4255
+ return createPostgresIntrospectionProvider({
4256
+ connectionString: config.connectionString,
4257
+ database: config.database,
4258
+ schemas: normalizeSchemaSelection(config.schemas)
4259
+ });
4260
+ }
4261
+ function resolveGeneratorProvider(providerConfig, experimentalFlags) {
4262
+ if (providerConfig.kind === "postgres" && providerConfig.mode === "direct") {
4263
+ return createPostgresProvider(providerConfig);
4264
+ }
4265
+ if (providerConfig.kind === "postgres" && providerConfig.mode === "gateway") {
4266
+ return new AthenaGatewayPostgresIntrospectionProvider(providerConfig);
4267
+ }
4268
+ if (providerConfig.kind === "scylla") {
4269
+ if (!experimentalFlags.scyllaProviderContracts) {
4270
+ throw new Error(
4271
+ "Scylla provider contracts are disabled. Set experimental.scyllaProviderContracts=true to enable placeholders."
4272
+ );
3351
4273
  }
3352
- return {
3353
- ok: true,
3354
- status: response.status,
3355
- data: parsed ?? null,
3356
- error: null,
3357
- errorDetails: null,
3358
- raw: parsed
3359
- };
3360
- } catch (callError) {
3361
- const message = callError instanceof Error ? callError.message : String(callError);
3362
- const details = toErrorDetails({
3363
- code: "NETWORK_ERROR",
3364
- message: `Network error while calling ${context.method} ${context.endpoint}: ${message}`,
3365
- status: 0,
3366
- endpoint: context.endpoint,
3367
- method: context.method,
3368
- cause: message,
3369
- hint: "Check auth server URL, DNS, and network reachability."
3370
- });
3371
- return {
3372
- ok: false,
3373
- status: 0,
3374
- data: null,
3375
- error: details.message,
3376
- errorDetails: details,
3377
- raw: null
3378
- };
4274
+ return new ScyllaIntrospectionProvider(providerConfig);
3379
4275
  }
4276
+ throw new Error(`Unsupported generator provider kind: ${providerConfig.kind ?? "unknown"}`);
3380
4277
  }
3381
- function executePostWithCompatibleInput(config, context, input, options) {
3382
- const { payload, fetchOptions } = extractFetchOptions(input);
3383
- const mergedOptions = mergeCallOptions(fetchOptions, options);
3384
- return callAuthEndpoint(config, context, payload ?? {}, void 0, mergedOptions);
3385
- }
3386
- function executePostWithOptionalInput(config, context, input, options) {
3387
- const { fetchOptions } = extractFetchOptions(input);
3388
- const mergedOptions = mergeCallOptions(fetchOptions, options);
3389
- return callAuthEndpoint(config, context, {}, void 0, mergedOptions);
3390
- }
3391
- function executeGetWithCompatibleInput(config, context, input, options) {
3392
- const { fetchOptions } = extractFetchOptions(input);
3393
- const mergedOptions = mergeCallOptions(fetchOptions, options);
3394
- return callAuthEndpoint(config, context, void 0, void 0, mergedOptions);
4278
+ async function writeArtifacts(files, cwd) {
4279
+ const writtenFiles = [];
4280
+ for (const file of files) {
4281
+ const absolutePath = path.resolve(cwd, file.path);
4282
+ await promises.mkdir(path.dirname(absolutePath), { recursive: true });
4283
+ await promises.writeFile(absolutePath, file.content, "utf8");
4284
+ writtenFiles.push(file.path);
4285
+ }
4286
+ return writtenFiles;
3395
4287
  }
3396
- function createAuthClient(config = {}) {
3397
- const normalizedBaseUrl = normalizeBaseUrl(config.baseUrl);
3398
- const resolvedConfig = {
3399
- ...config,
3400
- baseUrl: normalizedBaseUrl
3401
- };
3402
- const request = (input, options) => {
3403
- const method = input.method ?? (input.body !== void 0 ? "POST" : inferDefaultMethod(input.endpoint));
3404
- const mergedOptions = mergeCallOptions(input.fetchOptions, options);
3405
- return callAuthEndpoint(
3406
- resolvedConfig,
3407
- { endpoint: input.endpoint, method },
3408
- input.body,
3409
- input.query,
3410
- mergedOptions
3411
- );
3412
- };
3413
- const signOut = (input, options) => executePostWithOptionalInput(
3414
- resolvedConfig,
3415
- { endpoint: "/sign-out", method: "POST" },
3416
- input,
3417
- options
3418
- );
3419
- const revokeSessions = (input, options) => executePostWithOptionalInput(
3420
- resolvedConfig,
3421
- { endpoint: "/revoke-sessions", method: "POST" },
3422
- input,
3423
- options
3424
- );
3425
- const revokeOtherSessions = (input, options) => executePostWithOptionalInput(
3426
- resolvedConfig,
3427
- { endpoint: "/revoke-other-sessions", method: "POST" },
3428
- input,
3429
- options
3430
- );
3431
- const revokeSession = (input, options) => executePostWithCompatibleInput(
3432
- resolvedConfig,
3433
- { endpoint: "/revoke-session", method: "POST" },
3434
- input,
3435
- options
3436
- );
3437
- const deleteUser = (input, options) => {
3438
- const { payload, fetchOptions } = extractFetchOptions(input);
3439
- const mergedOptions = mergeCallOptions(fetchOptions, options);
3440
- return callAuthEndpoint(
3441
- resolvedConfig,
3442
- { endpoint: "/delete-user", method: "POST" },
3443
- payload ?? {},
3444
- void 0,
3445
- mergedOptions
3446
- );
3447
- };
3448
- const deleteUserCallback = (input, options) => {
3449
- const { payload, fetchOptions } = extractFetchOptions(input);
3450
- const mergedOptions = mergeCallOptions(fetchOptions, options);
3451
- const query = payload ?? {};
3452
- return callAuthEndpoint(
3453
- resolvedConfig,
3454
- { endpoint: "/delete-user/callback", method: "GET" },
3455
- void 0,
3456
- {
3457
- token: query.token,
3458
- callbackURL: query.callbackURL
3459
- },
3460
- mergedOptions
3461
- );
3462
- };
3463
- const resolveResetPasswordToken = (input, options) => {
3464
- const { payload, fetchOptions } = extractFetchOptions(input);
3465
- const mergedOptions = mergeCallOptions(fetchOptions, options);
3466
- const query = payload;
3467
- const token = query?.token?.trim();
3468
- if (!token) {
3469
- throw new Error("resolveResetPasswordToken requires a non-empty token");
3470
- }
3471
- const endpoint = `/reset-password/${encodeURIComponent(token)}`;
3472
- return callAuthEndpoint(
3473
- resolvedConfig,
3474
- { endpoint, method: "GET" },
3475
- void 0,
3476
- query?.callbackURL ? { callbackURL: query.callbackURL } : void 0,
3477
- mergedOptions
3478
- );
4288
+ async function runSchemaGenerator(options = {}) {
4289
+ const cwd = options.cwd ?? process.cwd();
4290
+ const configOptions = {
4291
+ cwd,
4292
+ configPath: options.configPath
3479
4293
  };
4294
+ const { configPath, config } = await loadGeneratorConfig(configOptions);
4295
+ const provider = options.provider ?? resolveGeneratorProvider(config.provider, config.experimental);
4296
+ const snapshot = await provider.inspect({
4297
+ schemas: resolveProviderSchemas(config.provider)
4298
+ });
4299
+ const generated = generateArtifactsFromSnapshot(snapshot, config);
4300
+ const writtenFiles = options.dryRun ? [] : await writeArtifacts(generated.files, cwd);
3480
4301
  return {
3481
- baseUrl: normalizedBaseUrl,
3482
- request,
3483
- signIn: {
3484
- email: (input, options) => executePostWithCompatibleInput(
3485
- resolvedConfig,
3486
- { endpoint: "/sign-in/email", method: "POST" },
3487
- input,
3488
- options
3489
- ),
3490
- username: (input, options) => executePostWithCompatibleInput(
3491
- resolvedConfig,
3492
- { endpoint: "/sign-in/username", method: "POST" },
3493
- input,
3494
- options
3495
- ),
3496
- social: (input, options) => executePostWithCompatibleInput(
3497
- resolvedConfig,
3498
- { endpoint: "/sign-in/social", method: "POST" },
3499
- input,
3500
- options
3501
- )
3502
- },
3503
- signUp: {
3504
- email: (input, options) => executePostWithCompatibleInput(
3505
- resolvedConfig,
3506
- { endpoint: "/sign-up/email", method: "POST" },
3507
- input,
3508
- options
3509
- )
3510
- },
3511
- signOut,
3512
- logout: signOut,
3513
- getSession: (input, options) => executeGetWithCompatibleInput(
3514
- resolvedConfig,
3515
- { endpoint: "/get-session", method: "GET" },
3516
- input,
3517
- options
3518
- ),
3519
- listSessions: (input, options) => executeGetWithCompatibleInput(
3520
- resolvedConfig,
3521
- { endpoint: "/list-sessions", method: "GET" },
3522
- input,
3523
- options
3524
- ),
3525
- revokeSession,
3526
- clearSession: revokeSession,
3527
- revokeSessions,
3528
- clearSessions: revokeSessions,
3529
- revokeOtherSessions,
3530
- clearOtherSessions: revokeOtherSessions,
3531
- forgetPassword: (input, options) => executePostWithCompatibleInput(
3532
- resolvedConfig,
3533
- { endpoint: "/forget-password", method: "POST" },
3534
- input,
3535
- options
3536
- ),
3537
- resetPassword: (input, options) => executePostWithCompatibleInput(
3538
- resolvedConfig,
3539
- { endpoint: "/reset-password", method: "POST" },
3540
- input,
3541
- options
3542
- ),
3543
- resolveResetPasswordToken,
3544
- verifyEmail: (input, options) => {
3545
- const { payload, fetchOptions } = extractFetchOptions(input);
3546
- const mergedOptions = mergeCallOptions(fetchOptions, options);
3547
- const query = payload;
3548
- return callAuthEndpoint(
3549
- resolvedConfig,
3550
- { endpoint: "/verify-email", method: "GET" },
3551
- void 0,
3552
- query ? {
3553
- token: query.token,
3554
- callbackURL: query.callbackURL
3555
- } : void 0,
3556
- mergedOptions
3557
- );
3558
- },
3559
- sendVerificationEmail: (input, options) => executePostWithCompatibleInput(
3560
- resolvedConfig,
3561
- { endpoint: "/send-verification-email", method: "POST" },
3562
- input,
3563
- options
3564
- ),
3565
- changeEmail: (input, options) => executePostWithCompatibleInput(
3566
- resolvedConfig,
3567
- { endpoint: "/change-email", method: "POST" },
3568
- input,
3569
- options
3570
- ),
3571
- changePassword: (input, options) => executePostWithCompatibleInput(
3572
- resolvedConfig,
3573
- { endpoint: "/change-password", method: "POST" },
3574
- input,
3575
- options
3576
- ),
3577
- updateUser: (input, options) => executePostWithCompatibleInput(
3578
- resolvedConfig,
3579
- { endpoint: "/update-user", method: "POST" },
3580
- input,
3581
- options
3582
- ),
3583
- deleteUser,
3584
- deleteUserCallback,
3585
- linkSocial: (input, options) => executePostWithCompatibleInput(
3586
- resolvedConfig,
3587
- { endpoint: "/link-social", method: "POST" },
3588
- input,
3589
- options
3590
- ),
3591
- listAccounts: (input, options) => executeGetWithCompatibleInput(
3592
- resolvedConfig,
3593
- { endpoint: "/list-accounts", method: "GET" },
3594
- input,
3595
- options
3596
- ),
3597
- unlinkAccount: (input, options) => executePostWithCompatibleInput(
3598
- resolvedConfig,
3599
- { endpoint: "/unlink-account", method: "POST" },
3600
- input,
3601
- options
3602
- ),
3603
- refreshToken: (input, options) => executePostWithCompatibleInput(
3604
- resolvedConfig,
3605
- { endpoint: "/refresh-token", method: "POST" },
3606
- input,
3607
- options
3608
- ),
3609
- getAccessToken: (input, options) => executePostWithCompatibleInput(
3610
- resolvedConfig,
3611
- { endpoint: "/get-access-token", method: "POST" },
3612
- input,
3613
- options
3614
- )
4302
+ ...generated,
4303
+ configPath,
4304
+ writtenFiles
3615
4305
  };
3616
4306
  }
3617
4307
 
@@ -3627,6 +4317,7 @@ exports.assertInt = assertInt;
3627
4317
  exports.coerceInt = coerceInt;
3628
4318
  exports.createAuthClient = createAuthClient;
3629
4319
  exports.createClient = createClient;
4320
+ exports.createModelFormAdapter = createModelFormAdapter;
3630
4321
  exports.createPostgresIntrospectionProvider = createPostgresIntrospectionProvider;
3631
4322
  exports.createTypedClient = createTypedClient;
3632
4323
  exports.defineDatabase = defineDatabase;
@@ -3643,12 +4334,15 @@ exports.loadGeneratorConfig = loadGeneratorConfig;
3643
4334
  exports.normalizeAthenaError = normalizeAthenaError;
3644
4335
  exports.normalizeGeneratorConfig = normalizeGeneratorConfig;
3645
4336
  exports.normalizeSchemaSelection = normalizeSchemaSelection;
4337
+ exports.parseBooleanFlag = parseBooleanFlag;
3646
4338
  exports.requireAffected = requireAffected;
3647
4339
  exports.requireSuccess = requireSuccess;
3648
4340
  exports.resolveGeneratorProvider = resolveGeneratorProvider;
3649
4341
  exports.resolvePostgresColumnType = resolvePostgresColumnType;
3650
4342
  exports.resolveProviderSchemas = resolveProviderSchemas;
3651
4343
  exports.runSchemaGenerator = runSchemaGenerator;
4344
+ exports.toModelFormDefaults = toModelFormDefaults;
4345
+ exports.toModelPayload = toModelPayload;
3652
4346
  exports.unwrap = unwrap;
3653
4347
  exports.unwrapOne = unwrapOne;
3654
4348
  exports.unwrapRows = unwrapRows;