@supatype/client 0.1.0-alpha.6
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/.turbo/turbo-build.log +4 -0
- package/.turbo/turbo-test.log +7 -0
- package/.turbo/turbo-typecheck.log +4 -0
- package/dist/auth.d.ts +243 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +560 -0
- package/dist/auth.js.map +1 -0
- package/dist/error-codes-doc.d.ts +31 -0
- package/dist/error-codes-doc.d.ts.map +1 -0
- package/dist/error-codes-doc.js +294 -0
- package/dist/error-codes-doc.js.map +1 -0
- package/dist/errors.d.ts +197 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +162 -0
- package/dist/errors.js.map +1 -0
- package/dist/fetch-with-retry.d.ts +49 -0
- package/dist/fetch-with-retry.d.ts.map +1 -0
- package/dist/fetch-with-retry.js +150 -0
- package/dist/fetch-with-retry.js.map +1 -0
- package/dist/index.d.ts +137 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +225 -0
- package/dist/index.js.map +1 -0
- package/dist/query.d.ts +53 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +216 -0
- package/dist/query.js.map +1 -0
- package/dist/realtime.d.ts +69 -0
- package/dist/realtime.d.ts.map +1 -0
- package/dist/realtime.js +279 -0
- package/dist/realtime.js.map +1 -0
- package/dist/retry.d.ts +24 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +25 -0
- package/dist/retry.js.map +1 -0
- package/dist/serverless-docs.d.ts +38 -0
- package/dist/serverless-docs.d.ts.map +1 -0
- package/dist/serverless-docs.js +83 -0
- package/dist/serverless-docs.js.map +1 -0
- package/dist/storage.d.ts +79 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +130 -0
- package/dist/storage.js.map +1 -0
- package/dist/types.d.ts +141 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +26 -0
- package/src/auth.ts +713 -0
- package/src/error-codes-doc.ts +315 -0
- package/src/errors.ts +201 -0
- package/src/fetch-with-retry.ts +200 -0
- package/src/index.ts +418 -0
- package/src/query.ts +280 -0
- package/src/realtime.ts +418 -0
- package/src/retry.ts +35 -0
- package/src/serverless-docs.ts +107 -0
- package/src/storage.ts +182 -0
- package/src/types.ts +184 -0
- package/tests/auth.test.ts +282 -0
- package/tests/mfa-totp-integration.test.ts +359 -0
- package/tests/query.test.ts +286 -0
- package/tests/rate-limit-integration.test.ts +185 -0
- package/tests/realtime-multi-tenant-integration.test.ts +372 -0
- package/tests/retry-integration.test.ts +212 -0
- package/tests/serverless.test.ts +115 -0
- package/tests/storage-quota-integration.test.ts +189 -0
- package/tests/storage-upload-limit-integration.test.ts +185 -0
- package/tests/types.test.ts +123 -0
- package/tsconfig.json +11 -0
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,SAAS,GAAG,iCAAiC,CAAA;AAEnD;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,IAAI,CAAQ;IACZ,OAAO,CAAQ;IACf,UAAU,CAAqB;IAExC,YAAY,OAAe,EAAE,IAAY,EAAE,UAAmB;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,eAAe,CAAA;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,OAAO,GAAG,GAAG,SAAS,IAAI,IAAI,CAAC,WAAW,EAAE,EAAE,CAAA;IACrD,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,aAAa;IAC1C,YAAY,OAAe,EAAE,OAAe,YAAY,EAAE,UAAmB;QAC3E,K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B,kDAAkD;IAClD,aAAa,EAAE,UAAU;IACzB,iDAAiD;IACjD,iBAAiB,EAAE,UAAU;IAC7B,4BAA4B;IAC5B,YAAY,EAAE,YAAY;IAC1B,kCAAkC;IAClC,gBAAgB,EAAE,YAAY;IAC9B,oCAAoC;IACpC,kBAAkB,EAAE,YAAY;IAChC,iCAAiC;IACjC,eAAe,EAAE,YAAY;IAC7B,2BAA2B;IAC3B,aAAa,EAAE,YAAY;IAC3B,sBAAsB;IACtB,eAAe,EAAE,YAAY;IAC7B,uBAAuB;IACvB,gBAAgB,EAAE,YAAY;CACtB,CAAA;AAEV,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,kCAAkC;IAClC,iBAAiB,EAAE,4BAA4B;IAC/C,yCAAyC;IACzC,mBAAmB,EAAE,8BAA8B;IACnD,gCAAgC;IAChC,aAAa,EAAE,wBAAwB;IACvC,wDAAwD;IACxD,gBAAgB,EAAE,2BAA2B;IAC7C,8CAA8C;IAC9C,iBAAiB,EAAE,4BAA4B;CACvC,CAAA;AAEV,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,OAAO,EAAE,iBAAiB;IAC1B,kBAAkB,EAAE,4BAA4B;IAChD,WAAW,EAAE,qBAAqB;CAC1B,CAAA;AAEV,wEAAwE;AACxE,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,cAAc;IACpB,SAAS,EAAE,mBAAmB;IAC9B,OAAO,EAAE,iBAAiB;IAC1B,QAAQ,EAAE,kBAAkB;IAC5B,OAAO,EAAE,iBAAiB;CAClB,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch wrapper with automatic retry, rate limit handling, and timeout.
|
|
3
|
+
*/
|
|
4
|
+
export interface FetchOptions {
|
|
5
|
+
/** Maximum number of retries for transient errors. Default: 3. */
|
|
6
|
+
maxRetries?: number | undefined;
|
|
7
|
+
/** Request timeout in milliseconds. Default: 30000. */
|
|
8
|
+
timeout?: number | undefined;
|
|
9
|
+
/** Disable automatic retry. */
|
|
10
|
+
retry?: boolean | undefined;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Fetch with automatic retry for transient errors and rate limit handling.
|
|
14
|
+
*
|
|
15
|
+
* Retries on:
|
|
16
|
+
* - Network errors (connection refused, timeout, DNS)
|
|
17
|
+
* - 5xx server errors
|
|
18
|
+
*
|
|
19
|
+
* Does NOT retry:
|
|
20
|
+
* - 4xx client errors (except 429 which is handled specially)
|
|
21
|
+
*/
|
|
22
|
+
export declare function fetchWithRetry(url: string, init?: RequestInit & FetchOptions): Promise<Response>;
|
|
23
|
+
export interface ServerlessDetectionResult {
|
|
24
|
+
/** Whether a serverless environment was detected. */
|
|
25
|
+
detected: boolean;
|
|
26
|
+
/** Name of the detected platform, or `null` when not detected. */
|
|
27
|
+
platform: string | null;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Detect whether the SDK is running inside a known serverless environment by
|
|
31
|
+
* inspecting well-known environment variables.
|
|
32
|
+
*
|
|
33
|
+
* Returns the platform name when detected so callers can include it in
|
|
34
|
+
* diagnostics or warnings.
|
|
35
|
+
*/
|
|
36
|
+
export declare function detectServerlessEnvironment(): ServerlessDetectionResult;
|
|
37
|
+
/**
|
|
38
|
+
* Log a one-time warning when the SDK detects a serverless environment **and**
|
|
39
|
+
* the provided URL looks like a direct Postgres connection string rather than
|
|
40
|
+
* the Supatype HTTP gateway.
|
|
41
|
+
*
|
|
42
|
+
* Direct database connections are problematic in serverless contexts because
|
|
43
|
+
* each invocation may open a new TCP connection, quickly exhausting the
|
|
44
|
+
* database's connection limit.
|
|
45
|
+
*
|
|
46
|
+
* The warning is emitted at most once per process to avoid log noise.
|
|
47
|
+
*/
|
|
48
|
+
export declare function warnIfServerlessDirectConnection(url: string): void;
|
|
49
|
+
//# sourceMappingURL=fetch-with-retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-with-retry.d.ts","sourceRoot":"","sources":["../src/fetch-with-retry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,WAAW,YAAY;IAC3B,kEAAkE;IAClE,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC/B,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,+BAA+B;IAC/B,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,CAAA;CAC5B;AAMD;;;;;;;;;GASG;AACH,wBAAsB,cAAc,CAClC,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,WAAW,GAAG,YAAY,GAChC,OAAO,CAAC,QAAQ,CAAC,CAyEnB;AA0BD,MAAM,WAAW,yBAAyB;IACxC,qDAAqD;IACrD,QAAQ,EAAE,OAAO,CAAA;IACjB,kEAAkE;IAClE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;CACxB;AAED;;;;;;GAMG;AACH,wBAAgB,2BAA2B,IAAI,yBAAyB,CAevE;AAID;;;;;;;;;;GAUG;AACH,wBAAgB,gCAAgC,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAwBlE"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch wrapper with automatic retry, rate limit handling, and timeout.
|
|
3
|
+
*/
|
|
4
|
+
import { NetworkError, RateLimitError, SupatypeError, NetworkErrorCodes } from "./errors.js";
|
|
5
|
+
const DEFAULT_MAX_RETRIES = 3;
|
|
6
|
+
const DEFAULT_TIMEOUT = 30000;
|
|
7
|
+
const RETRY_DELAYS = [200, 1000, 3000];
|
|
8
|
+
/**
|
|
9
|
+
* Fetch with automatic retry for transient errors and rate limit handling.
|
|
10
|
+
*
|
|
11
|
+
* Retries on:
|
|
12
|
+
* - Network errors (connection refused, timeout, DNS)
|
|
13
|
+
* - 5xx server errors
|
|
14
|
+
*
|
|
15
|
+
* Does NOT retry:
|
|
16
|
+
* - 4xx client errors (except 429 which is handled specially)
|
|
17
|
+
*/
|
|
18
|
+
export async function fetchWithRetry(url, init) {
|
|
19
|
+
const maxRetries = init?.retry === false ? 0 : (init?.maxRetries ?? DEFAULT_MAX_RETRIES);
|
|
20
|
+
const timeout = init?.timeout ?? DEFAULT_TIMEOUT;
|
|
21
|
+
let lastError;
|
|
22
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
23
|
+
try {
|
|
24
|
+
const controller = new AbortController();
|
|
25
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
26
|
+
const response = await fetch(url, {
|
|
27
|
+
...init,
|
|
28
|
+
signal: controller.signal,
|
|
29
|
+
});
|
|
30
|
+
clearTimeout(timeoutId);
|
|
31
|
+
// Handle rate limiting
|
|
32
|
+
if (response.status === 429) {
|
|
33
|
+
const retryAfter = parseInt(response.headers.get("Retry-After") || "5", 10);
|
|
34
|
+
if (attempt < maxRetries) {
|
|
35
|
+
await sleep(retryAfter * 1000);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
throw new RateLimitError(retryAfter);
|
|
39
|
+
}
|
|
40
|
+
// Retry on 5xx server errors
|
|
41
|
+
if (response.status >= 500 && attempt < maxRetries) {
|
|
42
|
+
await sleep(RETRY_DELAYS[attempt] ?? 3000);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
return response;
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
if (err instanceof RateLimitError)
|
|
49
|
+
throw err;
|
|
50
|
+
if (err instanceof SupatypeError)
|
|
51
|
+
throw err;
|
|
52
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
53
|
+
// Classify the error
|
|
54
|
+
if (lastError.name === "AbortError") {
|
|
55
|
+
throw new NetworkError(`Request timed out after ${timeout}ms`, NetworkErrorCodes.TIMEOUT);
|
|
56
|
+
}
|
|
57
|
+
// Retry on network errors
|
|
58
|
+
if (attempt < maxRetries) {
|
|
59
|
+
await sleep(RETRY_DELAYS[attempt] ?? 3000);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
// Classify and throw
|
|
63
|
+
const message = lastError.message.toLowerCase();
|
|
64
|
+
if (message.includes("econnrefused")) {
|
|
65
|
+
throw new NetworkError(`Connection refused: ${url}`, NetworkErrorCodes.CONNECTION_REFUSED);
|
|
66
|
+
}
|
|
67
|
+
if (message.includes("enotfound") || message.includes("dns")) {
|
|
68
|
+
throw new NetworkError(`DNS lookup failed: ${url}`, NetworkErrorCodes.DNS_FAILURE);
|
|
69
|
+
}
|
|
70
|
+
throw new NetworkError(lastError.message);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
throw new NetworkError(lastError?.message || "Request failed after retries");
|
|
74
|
+
}
|
|
75
|
+
function sleep(ms) {
|
|
76
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
77
|
+
}
|
|
78
|
+
// ─── Serverless environment detection ────────────────────────────────────────
|
|
79
|
+
/**
|
|
80
|
+
* Known serverless environment indicators keyed by platform name.
|
|
81
|
+
* Each entry maps to an env-var check: either the var must exist (value `undefined`)
|
|
82
|
+
* or it must equal the specified string.
|
|
83
|
+
*/
|
|
84
|
+
const SERVERLESS_ENV_VARS = [
|
|
85
|
+
{ name: "Vercel", envVar: "VERCEL", expected: "1" },
|
|
86
|
+
{ name: "AWS Lambda", envVar: "AWS_LAMBDA_FUNCTION_NAME" },
|
|
87
|
+
{ name: "Netlify", envVar: "NETLIFY", expected: "true" },
|
|
88
|
+
{ name: "Cloudflare Workers", envVar: "CF_PAGES" },
|
|
89
|
+
{ name: "Google Cloud Functions", envVar: "FUNCTION_TARGET" },
|
|
90
|
+
{ name: "Azure Functions", envVar: "FUNCTIONS_WORKER_RUNTIME" },
|
|
91
|
+
{ name: "Deno Deploy", envVar: "DENO_DEPLOYMENT_ID" },
|
|
92
|
+
{ name: "Railway", envVar: "RAILWAY_ENVIRONMENT" },
|
|
93
|
+
{ name: "Render", envVar: "RENDER" },
|
|
94
|
+
{ name: "Fly.io", envVar: "FLY_APP_NAME" },
|
|
95
|
+
];
|
|
96
|
+
/**
|
|
97
|
+
* Detect whether the SDK is running inside a known serverless environment by
|
|
98
|
+
* inspecting well-known environment variables.
|
|
99
|
+
*
|
|
100
|
+
* Returns the platform name when detected so callers can include it in
|
|
101
|
+
* diagnostics or warnings.
|
|
102
|
+
*/
|
|
103
|
+
export function detectServerlessEnvironment() {
|
|
104
|
+
// Guard: `process` may not exist in browser/edge contexts.
|
|
105
|
+
if (typeof process === "undefined" || process.env === undefined) {
|
|
106
|
+
return { detected: false, platform: null };
|
|
107
|
+
}
|
|
108
|
+
for (const entry of SERVERLESS_ENV_VARS) {
|
|
109
|
+
const value = process.env[entry.envVar];
|
|
110
|
+
if (value === undefined)
|
|
111
|
+
continue;
|
|
112
|
+
if (entry.expected === undefined || value === entry.expected) {
|
|
113
|
+
return { detected: true, platform: entry.name };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return { detected: false, platform: null };
|
|
117
|
+
}
|
|
118
|
+
const SERVERLESS_WARNING_ISSUED = { value: false };
|
|
119
|
+
/**
|
|
120
|
+
* Log a one-time warning when the SDK detects a serverless environment **and**
|
|
121
|
+
* the provided URL looks like a direct Postgres connection string rather than
|
|
122
|
+
* the Supatype HTTP gateway.
|
|
123
|
+
*
|
|
124
|
+
* Direct database connections are problematic in serverless contexts because
|
|
125
|
+
* each invocation may open a new TCP connection, quickly exhausting the
|
|
126
|
+
* database's connection limit.
|
|
127
|
+
*
|
|
128
|
+
* The warning is emitted at most once per process to avoid log noise.
|
|
129
|
+
*/
|
|
130
|
+
export function warnIfServerlessDirectConnection(url) {
|
|
131
|
+
if (SERVERLESS_WARNING_ISSUED.value)
|
|
132
|
+
return;
|
|
133
|
+
const { detected, platform } = detectServerlessEnvironment();
|
|
134
|
+
if (!detected)
|
|
135
|
+
return;
|
|
136
|
+
// Check if the URL resembles a direct Postgres connection string
|
|
137
|
+
const lowerUrl = url.toLowerCase();
|
|
138
|
+
const isDirectConnection = lowerUrl.startsWith("postgres://") ||
|
|
139
|
+
lowerUrl.startsWith("postgresql://") ||
|
|
140
|
+
// Port 5432 or 6543 (pgbouncer) on a bare hostname hints at direct PG access
|
|
141
|
+
/:\d{4,5}\/\w/.test(url);
|
|
142
|
+
if (!isDirectConnection)
|
|
143
|
+
return;
|
|
144
|
+
SERVERLESS_WARNING_ISSUED.value = true;
|
|
145
|
+
const prefix = platform !== null ? `[Supatype] Serverless environment detected (${platform}). ` : "[Supatype] ";
|
|
146
|
+
console.warn(prefix +
|
|
147
|
+
"Direct database connections are not recommended in serverless environments. " +
|
|
148
|
+
"Use the Supatype client SDK instead.");
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=fetch-with-retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-with-retry.js","sourceRoot":"","sources":["../src/fetch-with-retry.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAW5F,MAAM,mBAAmB,GAAG,CAAC,CAAA;AAC7B,MAAM,eAAe,GAAG,KAAK,CAAA;AAC7B,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAA;AAEtC;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,GAAW,EACX,IAAiC;IAEjC,MAAM,UAAU,GAAG,IAAI,EAAE,KAAK,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,UAAU,IAAI,mBAAmB,CAAC,CAAA;IACxF,MAAM,OAAO,GAAG,IAAI,EAAE,OAAO,IAAI,eAAe,CAAA;IAChD,IAAI,SAA4B,CAAA;IAEhC,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,OAAO,IAAI,UAAU,EAAE,OAAO,EAAE,EAAE,CAAC;QACvD,IA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,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;AAC5C,CAAC;AAED,MAAM,yBAAyB,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,CAAA;AAElD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,gCAAgC,CAAC,GAAW;IAC1D,IAAI,yBAAyB,CAAC,KAAK;QAAE,OAAM;IAE3C,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,2BAA2B,EAAE,CAAA;IAC5D,IAAI,CAAC,QAAQ;QAAE,OAAM;IAErB,iEAAiE;IACjE,MAAM,QAAQ,GAAG,GAAG,CAAC,WAAW,EAAE,CAAA;IAClC,MAAM,kBAAkB,GACtB,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC;QAClC,QAAQ,CAAC,UAAU,CAAC,eAAe,CAAC;QACpC,6EAA6E;QAC7E,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAE1B,IAAI,CAAC,kBAAkB;QAAE,OAAM;IAE/B,yBAAyB,CAAC,KAAK,GAAG,IAAI,CAAA;IAEtC,MAAM,MAAM,GAAG,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,+CAA+C,QAAQ,KAAK,CAAC,CAAC,CAAC,aAAa,CAAA;IAC/G,OAAO,CAAC,IAAI,CACV,MAAM;QACN,8EAA8E;QAC9E,sCAAsC,CACvC,CAAA;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { AuthClient } from "./auth.js";
|
|
2
|
+
import { QueryBuilder, MutationBuilder } from "./query.js";
|
|
3
|
+
import { StorageClient } from "./storage.js";
|
|
4
|
+
import { RealtimeClient } from "./realtime.js";
|
|
5
|
+
import type { AnyDatabase, FunctionDef, RpcResult, SupatypeClientConfig, SupatypeError } from "./types.js";
|
|
6
|
+
export type { User, Session, AuthChangeEvent, SupatypeError, QueryResult, RpcResult, AnyDatabase, SupatypeClientConfig, FunctionDef, TableDef, } from "./types.js";
|
|
7
|
+
export { AuthClient } from "./auth.js";
|
|
8
|
+
export { QueryBuilder, MutationBuilder } from "./query.js";
|
|
9
|
+
export { StorageClient, BucketClient } from "./storage.js";
|
|
10
|
+
export type { StorageObject, TransformOptions } from "./storage.js";
|
|
11
|
+
export { RealtimeClient } from "./realtime.js";
|
|
12
|
+
export type { RealtimeEvent, RealtimePayload, ChannelStatus, PresenceEntry } from "./realtime.js";
|
|
13
|
+
export * from "./errors.js";
|
|
14
|
+
export { fetchWithRetry, detectServerlessEnvironment, warnIfServerlessDirectConnection } from "./fetch-with-retry.js";
|
|
15
|
+
export type { FetchOptions, ServerlessDetectionResult } from "./fetch-with-retry.js";
|
|
16
|
+
export { createRetryFetch } from "./retry.js";
|
|
17
|
+
export type { RetryConfig } from "./retry.js";
|
|
18
|
+
export { ERROR_CODES_DOCUMENTATION, getErrorDocumentation, getErrorCodesByCategory } from "./error-codes-doc.js";
|
|
19
|
+
export type { ErrorCodeEntry } from "./error-codes-doc.js";
|
|
20
|
+
export { CONNECTION_MODES, SERVERLESS_CONNECTION_WARNING, CONNECTION_FAQ } from "./serverless-docs.js";
|
|
21
|
+
export type { ConnectionModeDoc } from "./serverless-docs.js";
|
|
22
|
+
interface TableDef {
|
|
23
|
+
Row: Record<string, unknown>;
|
|
24
|
+
Insert: Record<string, unknown>;
|
|
25
|
+
Update: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
declare class TableClient<TDef extends TableDef> {
|
|
28
|
+
private readonly baseUrl;
|
|
29
|
+
private readonly path;
|
|
30
|
+
private readonly headers;
|
|
31
|
+
constructor(baseUrl: string, table: string, headers: Record<string, string>);
|
|
32
|
+
/**
|
|
33
|
+
* Start a SELECT query.
|
|
34
|
+
*
|
|
35
|
+
* Pass a type parameter to narrow the result when embedding relations:
|
|
36
|
+
* ```ts
|
|
37
|
+
* client.from('posts').select<Post & { comments: Comment[] }>('*, comments(*)')
|
|
38
|
+
* ```
|
|
39
|
+
* Without a type parameter the full Row type is returned.
|
|
40
|
+
*/
|
|
41
|
+
select<TResult = TDef["Row"]>(columns?: string | undefined): QueryBuilder<TResult>;
|
|
42
|
+
insert(data: TDef["Insert"] | TDef["Insert"][]): MutationBuilder<TDef["Row"]>;
|
|
43
|
+
upsert(data: TDef["Insert"] | TDef["Insert"][]): MutationBuilder<TDef["Row"]>;
|
|
44
|
+
update(data: TDef["Update"]): MutationBuilder<TDef["Row"]>;
|
|
45
|
+
delete(): MutationBuilder<TDef["Row"]>;
|
|
46
|
+
}
|
|
47
|
+
export interface GlobalClient<TRow extends Record<string, unknown> = Record<string, unknown>> {
|
|
48
|
+
get(): Promise<{
|
|
49
|
+
data: TRow | null;
|
|
50
|
+
error: SupatypeError | null;
|
|
51
|
+
}>;
|
|
52
|
+
update(data: Partial<TRow>): Promise<{
|
|
53
|
+
data: TRow | null;
|
|
54
|
+
error: SupatypeError | null;
|
|
55
|
+
}>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Helper type: extract function names from a database type.
|
|
59
|
+
* Falls back to `string` when Functions is not defined.
|
|
60
|
+
*/
|
|
61
|
+
type FunctionNames<TDatabase extends AnyDatabase> = TDatabase["public"] extends {
|
|
62
|
+
Functions: infer F;
|
|
63
|
+
} ? F extends Record<string, FunctionDef> ? keyof F & string : string : string;
|
|
64
|
+
/**
|
|
65
|
+
* Helper type: extract the Args type for a named function.
|
|
66
|
+
* Falls back to `Record<string, unknown>` when not typed.
|
|
67
|
+
*/
|
|
68
|
+
type FunctionArgs<TDatabase extends AnyDatabase, TFn extends string> = TDatabase["public"] extends {
|
|
69
|
+
Functions: infer F;
|
|
70
|
+
} ? F extends Record<string, FunctionDef> ? TFn extends keyof F ? F[TFn]["Args"] : Record<string, unknown> : Record<string, unknown> : Record<string, unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* Helper type: extract the Returns type for a named function.
|
|
73
|
+
* Falls back to `unknown` when not typed.
|
|
74
|
+
*/
|
|
75
|
+
type FunctionReturns<TDatabase extends AnyDatabase, TFn extends string> = TDatabase["public"] extends {
|
|
76
|
+
Functions: infer F;
|
|
77
|
+
} ? F extends Record<string, FunctionDef> ? TFn extends keyof F ? F[TFn]["Returns"] : unknown : unknown : unknown;
|
|
78
|
+
export interface FunctionInvokeOptions {
|
|
79
|
+
/** HTTP method. Default: POST */
|
|
80
|
+
method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | undefined;
|
|
81
|
+
/** Request headers (merged with defaults) */
|
|
82
|
+
headers?: Record<string, string> | undefined;
|
|
83
|
+
/** Request body (JSON-serialisable) */
|
|
84
|
+
body?: unknown | undefined;
|
|
85
|
+
}
|
|
86
|
+
declare class FunctionsClient {
|
|
87
|
+
private readonly baseUrl;
|
|
88
|
+
private readonly headers;
|
|
89
|
+
private readonly doFetch;
|
|
90
|
+
constructor(baseUrl: string, headers: Record<string, string>, doFetch: (url: string, init?: RequestInit) => Promise<Response>);
|
|
91
|
+
/**
|
|
92
|
+
* Invoke an edge function by name.
|
|
93
|
+
*
|
|
94
|
+
* ```ts
|
|
95
|
+
* const { data, error } = await supatype.functions.invoke('process-order', {
|
|
96
|
+
* body: { items: [...], address: {...} },
|
|
97
|
+
* })
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* The current user's JWT is automatically included in the Authorization header.
|
|
101
|
+
*/
|
|
102
|
+
invoke<TResponse = unknown>(functionName: string, options?: FunctionInvokeOptions | undefined): Promise<{
|
|
103
|
+
data: TResponse | null;
|
|
104
|
+
error: SupatypeError | null;
|
|
105
|
+
}>;
|
|
106
|
+
}
|
|
107
|
+
export interface SupatypeClient<TDatabase extends AnyDatabase = AnyDatabase> {
|
|
108
|
+
from<TTable extends keyof TDatabase["public"]["Tables"] & string>(table: TTable): TableClient<TDatabase["public"]["Tables"][TTable]>;
|
|
109
|
+
global<TRow extends Record<string, unknown> = Record<string, unknown>>(name: string): GlobalClient<TRow>;
|
|
110
|
+
auth: AuthClient;
|
|
111
|
+
storage: StorageClient;
|
|
112
|
+
realtime: RealtimeClient;
|
|
113
|
+
functions: FunctionsClient;
|
|
114
|
+
graphql(query: string, variables?: Record<string, unknown> | undefined): Promise<{
|
|
115
|
+
data: unknown;
|
|
116
|
+
error: SupatypeError | null;
|
|
117
|
+
}>;
|
|
118
|
+
/**
|
|
119
|
+
* Call a Postgres function via PostgREST's `/rpc/function_name` endpoint.
|
|
120
|
+
*
|
|
121
|
+
* ```ts
|
|
122
|
+
* const { data, error } = await supatype.rpc('calculate_shipping', {
|
|
123
|
+
* weight: 2.5,
|
|
124
|
+
* country: 'GB',
|
|
125
|
+
* })
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* When the database type includes `Functions`, parameters and return type
|
|
129
|
+
* are fully typed.
|
|
130
|
+
*/
|
|
131
|
+
rpc<TFn extends FunctionNames<TDatabase>>(fn: TFn, params?: FunctionArgs<TDatabase, TFn> | undefined, options?: {
|
|
132
|
+
head?: boolean | undefined;
|
|
133
|
+
count?: "exact" | "planned" | "estimated" | undefined;
|
|
134
|
+
} | undefined): Promise<RpcResult<FunctionReturns<TDatabase, TFn>>>;
|
|
135
|
+
}
|
|
136
|
+
export declare function createClient<TDatabase extends AnyDatabase = AnyDatabase>(config: SupatypeClientConfig): SupatypeClient<TDatabase>;
|
|
137
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAI9C,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,YAAY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G,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,aAAa,CAAA;IACtB,QAAQ,EAAE,cAAc,CAAA;IACxB,SAAS,EAAE,eAAe,CAAA;IAC1B,OAAO,CACL,KAAK,EAAE,MAAM,EACb,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAC9C,OAAO,CAAC;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAAA;KAAE,CAAC,CAAA;IAC1D;;;;;;;;;;;;OAYG;IACH,GAAG,CAAC,GAAG,SAAS,aAAa,CAAC,SAAS,CAAC,EACtC,EAAE,EAAE,GAAG,EACP,MAAM,CAAC,EAAE,YAAY,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,SAAS,EACjD,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,CAAA;KAAE,GAAG,SAAS,GAC1G,OAAO,CAAC,SAAS,CAAC,eAAe,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;CACvD;AAED,wBAAgB,YAAY,CAAC,SAAS,SAAS,WAAW,GAAG,WAAW,EACtE,MAAM,EAAE,oBAAoB,GAC3B,cAAc,CAAC,SAAS,CAAC,CAwI3B"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { AuthClient } from "./auth.js";
|
|
2
|
+
import { QueryBuilder, MutationBuilder } from "./query.js";
|
|
3
|
+
import { StorageClient } from "./storage.js";
|
|
4
|
+
import { RealtimeClient } from "./realtime.js";
|
|
5
|
+
import { PostgrestError } from "./errors.js";
|
|
6
|
+
import { createRetryFetch } from "./retry.js";
|
|
7
|
+
import { warnIfServerlessDirectConnection } from "./fetch-with-retry.js";
|
|
8
|
+
export { AuthClient } from "./auth.js";
|
|
9
|
+
export { QueryBuilder, MutationBuilder } from "./query.js";
|
|
10
|
+
export { StorageClient, BucketClient } from "./storage.js";
|
|
11
|
+
export { RealtimeClient } from "./realtime.js";
|
|
12
|
+
export * from "./errors.js";
|
|
13
|
+
export { fetchWithRetry, detectServerlessEnvironment, warnIfServerlessDirectConnection } from "./fetch-with-retry.js";
|
|
14
|
+
export { createRetryFetch } from "./retry.js";
|
|
15
|
+
export { ERROR_CODES_DOCUMENTATION, getErrorDocumentation, getErrorCodesByCategory } from "./error-codes-doc.js";
|
|
16
|
+
export { CONNECTION_MODES, SERVERLESS_CONNECTION_WARNING, CONNECTION_FAQ } from "./serverless-docs.js";
|
|
17
|
+
class TableClient {
|
|
18
|
+
baseUrl;
|
|
19
|
+
path;
|
|
20
|
+
headers;
|
|
21
|
+
constructor(baseUrl, table, headers) {
|
|
22
|
+
this.baseUrl = baseUrl;
|
|
23
|
+
this.path = `/rest/v1/${table}`;
|
|
24
|
+
this.headers = headers;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Start a SELECT query.
|
|
28
|
+
*
|
|
29
|
+
* Pass a type parameter to narrow the result when embedding relations:
|
|
30
|
+
* ```ts
|
|
31
|
+
* client.from('posts').select<Post & { comments: Comment[] }>('*, comments(*)')
|
|
32
|
+
* ```
|
|
33
|
+
* Without a type parameter the full Row type is returned.
|
|
34
|
+
*/
|
|
35
|
+
select(columns) {
|
|
36
|
+
return new QueryBuilder(this.baseUrl, this.path, this.headers, columns);
|
|
37
|
+
}
|
|
38
|
+
insert(data) {
|
|
39
|
+
return new MutationBuilder(this.baseUrl, this.path, this.headers, "POST", data);
|
|
40
|
+
}
|
|
41
|
+
upsert(data) {
|
|
42
|
+
return new MutationBuilder(this.baseUrl, this.path, this.headers, "POST", data, { upsert: true });
|
|
43
|
+
}
|
|
44
|
+
update(data) {
|
|
45
|
+
return new MutationBuilder(this.baseUrl, this.path, this.headers, "PATCH", data);
|
|
46
|
+
}
|
|
47
|
+
delete() {
|
|
48
|
+
return new MutationBuilder(this.baseUrl, this.path, this.headers, "DELETE");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
class FunctionsClient {
|
|
52
|
+
baseUrl;
|
|
53
|
+
headers;
|
|
54
|
+
doFetch;
|
|
55
|
+
constructor(baseUrl, headers, doFetch) {
|
|
56
|
+
this.baseUrl = baseUrl;
|
|
57
|
+
this.headers = headers;
|
|
58
|
+
this.doFetch = doFetch;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Invoke an edge function by name.
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* const { data, error } = await supatype.functions.invoke('process-order', {
|
|
65
|
+
* body: { items: [...], address: {...} },
|
|
66
|
+
* })
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* The current user's JWT is automatically included in the Authorization header.
|
|
70
|
+
*/
|
|
71
|
+
async invoke(functionName, options) {
|
|
72
|
+
const method = options?.method ?? "POST";
|
|
73
|
+
const mergedHeaders = {
|
|
74
|
+
...this.headers,
|
|
75
|
+
...options?.headers,
|
|
76
|
+
};
|
|
77
|
+
const fetchOpts = {
|
|
78
|
+
method,
|
|
79
|
+
headers: mergedHeaders,
|
|
80
|
+
};
|
|
81
|
+
if (options?.body !== undefined && method !== "GET") {
|
|
82
|
+
fetchOpts.body = JSON.stringify(options.body);
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const res = await this.doFetch(`${this.baseUrl}/functions/v1/${functionName}`, fetchOpts);
|
|
86
|
+
if (!res.ok) {
|
|
87
|
+
const body = await res.json().catch(() => ({}));
|
|
88
|
+
return {
|
|
89
|
+
data: null,
|
|
90
|
+
error: {
|
|
91
|
+
message: typeof body["message"] === "string" ? body["message"] : `Function returned ${res.status}`,
|
|
92
|
+
status: res.status,
|
|
93
|
+
...(typeof body["code"] === "string" ? { code: body["code"] } : {}),
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const contentType = res.headers.get("content-type") ?? "";
|
|
98
|
+
if (contentType.includes("application/json")) {
|
|
99
|
+
const data = await res.json();
|
|
100
|
+
return { data, error: null };
|
|
101
|
+
}
|
|
102
|
+
// Return text for non-JSON responses
|
|
103
|
+
const text = await res.text();
|
|
104
|
+
return { data: text, error: null };
|
|
105
|
+
}
|
|
106
|
+
catch (e) {
|
|
107
|
+
return {
|
|
108
|
+
data: null,
|
|
109
|
+
error: { message: e instanceof Error ? e.message : "Network error" },
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
export function createClient(config) {
|
|
115
|
+
// Warn early if a direct Postgres URL is used in a serverless environment
|
|
116
|
+
warnIfServerlessDirectConnection(config.url);
|
|
117
|
+
const baseHeaders = {
|
|
118
|
+
apikey: config.anonKey,
|
|
119
|
+
"Content-Type": "application/json",
|
|
120
|
+
};
|
|
121
|
+
// Create a retry-aware fetch bound to client-level config
|
|
122
|
+
const doFetch = createRetryFetch({
|
|
123
|
+
retry: config.retry,
|
|
124
|
+
timeout: config.timeout,
|
|
125
|
+
});
|
|
126
|
+
const auth = new AuthClient(`${config.url}/auth/v1`, baseHeaders);
|
|
127
|
+
const storage = new StorageClient(`${config.url}/storage/v1`, baseHeaders);
|
|
128
|
+
const realtime = new RealtimeClient(`${config.url}/realtime/v1`, baseHeaders);
|
|
129
|
+
const functions = new FunctionsClient(config.url, baseHeaders, doFetch);
|
|
130
|
+
const getAuthHeaders = () => {
|
|
131
|
+
// The auth headers are merged dynamically so callers pick up fresh JWTs
|
|
132
|
+
// after sign-in. Internal reference to auth._setSession isn't exposed;
|
|
133
|
+
// instead we read currentSession via a closure.
|
|
134
|
+
return baseHeaders;
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
from(table) {
|
|
138
|
+
return new TableClient(config.url, table, getAuthHeaders());
|
|
139
|
+
},
|
|
140
|
+
global(name) {
|
|
141
|
+
const tableName = `_global_${name}`;
|
|
142
|
+
return {
|
|
143
|
+
async get() {
|
|
144
|
+
const tc = new TableClient(config.url, tableName, getAuthHeaders());
|
|
145
|
+
const result = await tc.select().limit(1).maybeSingle();
|
|
146
|
+
return { data: result.data ?? null, error: result.error };
|
|
147
|
+
},
|
|
148
|
+
async update(data) {
|
|
149
|
+
const tc = new TableClient(config.url, tableName, getAuthHeaders());
|
|
150
|
+
const result = await tc.upsert(data);
|
|
151
|
+
const row = Array.isArray(result.data) ? result.data[0] ?? null : null;
|
|
152
|
+
return { data: row, error: result.error };
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
auth,
|
|
157
|
+
storage,
|
|
158
|
+
realtime,
|
|
159
|
+
functions,
|
|
160
|
+
async graphql(query, variables) {
|
|
161
|
+
const body = { query };
|
|
162
|
+
if (variables !== undefined) {
|
|
163
|
+
body["variables"] = variables;
|
|
164
|
+
}
|
|
165
|
+
let res;
|
|
166
|
+
try {
|
|
167
|
+
res = await doFetch(`${config.url}/graphql/v1`, {
|
|
168
|
+
method: "POST",
|
|
169
|
+
headers: baseHeaders,
|
|
170
|
+
body: JSON.stringify(body),
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
return { data: null, error: { message: e instanceof Error ? e.message : "Network error" } };
|
|
175
|
+
}
|
|
176
|
+
const json = await res.json();
|
|
177
|
+
if (json["errors"] !== undefined) {
|
|
178
|
+
const errors = json["errors"];
|
|
179
|
+
return { data: json["data"] ?? null, error: { message: (errors[0]?.message ?? "GraphQL error") } };
|
|
180
|
+
}
|
|
181
|
+
return { data: json["data"] ?? null, error: null };
|
|
182
|
+
},
|
|
183
|
+
async rpc(fn, params, options) {
|
|
184
|
+
const headers = { ...getAuthHeaders() };
|
|
185
|
+
const method = options?.head === true ? "HEAD" : "POST";
|
|
186
|
+
if (options?.count !== undefined) {
|
|
187
|
+
headers["Prefer"] = `count=${options.count}`;
|
|
188
|
+
}
|
|
189
|
+
let res;
|
|
190
|
+
try {
|
|
191
|
+
res = await doFetch(`${config.url}/rest/v1/rpc/${fn}`, {
|
|
192
|
+
method,
|
|
193
|
+
headers,
|
|
194
|
+
...(params !== undefined && method !== "HEAD" && { body: JSON.stringify(params) }),
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
catch (e) {
|
|
198
|
+
return { data: null, error: { message: e instanceof Error ? e.message : "Network error" } };
|
|
199
|
+
}
|
|
200
|
+
if (!res.ok) {
|
|
201
|
+
const body = await res.json().catch(() => ({}));
|
|
202
|
+
const pgError = PostgrestError.fromResponse({
|
|
203
|
+
message: typeof body["message"] === "string" ? body["message"] : undefined,
|
|
204
|
+
code: typeof body["code"] === "string" ? body["code"] : undefined,
|
|
205
|
+
details: typeof body["details"] === "string" ? body["details"] : undefined,
|
|
206
|
+
hint: typeof body["hint"] === "string" ? body["hint"] : undefined,
|
|
207
|
+
}, res.status);
|
|
208
|
+
return {
|
|
209
|
+
data: null,
|
|
210
|
+
error: {
|
|
211
|
+
message: pgError.message,
|
|
212
|
+
status: pgError.statusCode,
|
|
213
|
+
code: pgError.code,
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
if (method === "HEAD" || res.status === 204) {
|
|
218
|
+
return { data: null, error: null };
|
|
219
|
+
}
|
|
220
|
+
const data = await res.json();
|
|
221
|
+
return { data, error: null };
|
|
222
|
+
},
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MA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