@supacloud/lite 0.2.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.
Files changed (108) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/LICENSE +201 -0
  3. package/LICENSES/PGLITE-APACHE-2.0.txt +176 -0
  4. package/LICENSES/TINBASE-MIT.txt +21 -0
  5. package/README.md +170 -0
  6. package/RELEASING.md +22 -0
  7. package/THIRD_PARTY_NOTICES.md +24 -0
  8. package/dist/cli.js +9018 -0
  9. package/dist/index.d.ts +13 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +8469 -0
  12. package/dist/project-runtime.d.ts +65 -0
  13. package/dist/project-runtime.d.ts.map +1 -0
  14. package/dist/vendor/tinbase/auth/handler.d.ts +140 -0
  15. package/dist/vendor/tinbase/auth/handler.d.ts.map +1 -0
  16. package/dist/vendor/tinbase/auth/inbox.d.ts +34 -0
  17. package/dist/vendor/tinbase/auth/inbox.d.ts.map +1 -0
  18. package/dist/vendor/tinbase/auth/oauth.d.ts +88 -0
  19. package/dist/vendor/tinbase/auth/oauth.d.ts.map +1 -0
  20. package/dist/vendor/tinbase/auth/password.d.ts +9 -0
  21. package/dist/vendor/tinbase/auth/password.d.ts.map +1 -0
  22. package/dist/vendor/tinbase/auth/qr.d.ts +9 -0
  23. package/dist/vendor/tinbase/auth/qr.d.ts.map +1 -0
  24. package/dist/vendor/tinbase/auth/rate-limit.d.ts +34 -0
  25. package/dist/vendor/tinbase/auth/rate-limit.d.ts.map +1 -0
  26. package/dist/vendor/tinbase/auth/redirect.d.ts +21 -0
  27. package/dist/vendor/tinbase/auth/redirect.d.ts.map +1 -0
  28. package/dist/vendor/tinbase/auth/settings.d.ts +56 -0
  29. package/dist/vendor/tinbase/auth/settings.d.ts.map +1 -0
  30. package/dist/vendor/tinbase/auth/totp.d.ts +20 -0
  31. package/dist/vendor/tinbase/auth/totp.d.ts.map +1 -0
  32. package/dist/vendor/tinbase/cron/service.d.ts +47 -0
  33. package/dist/vendor/tinbase/cron/service.d.ts.map +1 -0
  34. package/dist/vendor/tinbase/db/bootstrap.d.ts +21 -0
  35. package/dist/vendor/tinbase/db/bootstrap.d.ts.map +1 -0
  36. package/dist/vendor/tinbase/db/database.d.ts +168 -0
  37. package/dist/vendor/tinbase/db/database.d.ts.map +1 -0
  38. package/dist/vendor/tinbase/db/emulated.d.ts +53 -0
  39. package/dist/vendor/tinbase/db/emulated.d.ts.map +1 -0
  40. package/dist/vendor/tinbase/db/engine.d.ts +47 -0
  41. package/dist/vendor/tinbase/db/engine.d.ts.map +1 -0
  42. package/dist/vendor/tinbase/db/inspect.d.ts +19 -0
  43. package/dist/vendor/tinbase/db/inspect.d.ts.map +1 -0
  44. package/dist/vendor/tinbase/db/pglite-engine.d.ts +9 -0
  45. package/dist/vendor/tinbase/db/pglite-engine.d.ts.map +1 -0
  46. package/dist/vendor/tinbase/db/schema-diff.d.ts +32 -0
  47. package/dist/vendor/tinbase/db/schema-diff.d.ts.map +1 -0
  48. package/dist/vendor/tinbase/db/sql-compat.d.ts +33 -0
  49. package/dist/vendor/tinbase/db/sql-compat.d.ts.map +1 -0
  50. package/dist/vendor/tinbase/functions/deno-shim.d.ts +15 -0
  51. package/dist/vendor/tinbase/functions/deno-shim.d.ts.map +1 -0
  52. package/dist/vendor/tinbase/functions/handler.d.ts +36 -0
  53. package/dist/vendor/tinbase/functions/handler.d.ts.map +1 -0
  54. package/dist/vendor/tinbase/gen-types.d.ts +23 -0
  55. package/dist/vendor/tinbase/gen-types.d.ts.map +1 -0
  56. package/dist/vendor/tinbase/index.d.ts +82 -0
  57. package/dist/vendor/tinbase/index.d.ts.map +1 -0
  58. package/dist/vendor/tinbase/jwt.d.ts +31 -0
  59. package/dist/vendor/tinbase/jwt.d.ts.map +1 -0
  60. package/dist/vendor/tinbase/log-buffer.d.ts +28 -0
  61. package/dist/vendor/tinbase/log-buffer.d.ts.map +1 -0
  62. package/dist/vendor/tinbase/net/service.d.ts +72 -0
  63. package/dist/vendor/tinbase/net/service.d.ts.map +1 -0
  64. package/dist/vendor/tinbase/node/bun-server.d.ts +23 -0
  65. package/dist/vendor/tinbase/node/bun-server.d.ts.map +1 -0
  66. package/dist/vendor/tinbase/node/bundle-function.d.ts +8 -0
  67. package/dist/vendor/tinbase/node/bundle-function.d.ts.map +1 -0
  68. package/dist/vendor/tinbase/node/config-toml.d.ts +34 -0
  69. package/dist/vendor/tinbase/node/config-toml.d.ts.map +1 -0
  70. package/dist/vendor/tinbase/node/fs-driver.d.ts +27 -0
  71. package/dist/vendor/tinbase/node/fs-driver.d.ts.map +1 -0
  72. package/dist/vendor/tinbase/node/load-config.d.ts +82 -0
  73. package/dist/vendor/tinbase/node/load-config.d.ts.map +1 -0
  74. package/dist/vendor/tinbase/node/load-functions.d.ts +24 -0
  75. package/dist/vendor/tinbase/node/load-functions.d.ts.map +1 -0
  76. package/dist/vendor/tinbase/node/project.d.ts +21 -0
  77. package/dist/vendor/tinbase/node/project.d.ts.map +1 -0
  78. package/dist/vendor/tinbase/node/server-shared.d.ts +10 -0
  79. package/dist/vendor/tinbase/node/server-shared.d.ts.map +1 -0
  80. package/dist/vendor/tinbase/realtime/engine.d.ts +82 -0
  81. package/dist/vendor/tinbase/realtime/engine.d.ts.map +1 -0
  82. package/dist/vendor/tinbase/rest/build.d.ts +101 -0
  83. package/dist/vendor/tinbase/rest/build.d.ts.map +1 -0
  84. package/dist/vendor/tinbase/rest/errors.d.ts +11 -0
  85. package/dist/vendor/tinbase/rest/errors.d.ts.map +1 -0
  86. package/dist/vendor/tinbase/rest/handler.d.ts +28 -0
  87. package/dist/vendor/tinbase/rest/handler.d.ts.map +1 -0
  88. package/dist/vendor/tinbase/rest/parse.d.ts +95 -0
  89. package/dist/vendor/tinbase/rest/parse.d.ts.map +1 -0
  90. package/dist/vendor/tinbase/retention/service.d.ts +41 -0
  91. package/dist/vendor/tinbase/retention/service.d.ts.map +1 -0
  92. package/dist/vendor/tinbase/security.d.ts +23 -0
  93. package/dist/vendor/tinbase/security.d.ts.map +1 -0
  94. package/dist/vendor/tinbase/storage/driver.d.ts +17 -0
  95. package/dist/vendor/tinbase/storage/driver.d.ts.map +1 -0
  96. package/dist/vendor/tinbase/storage/handler.d.ts +76 -0
  97. package/dist/vendor/tinbase/storage/handler.d.ts.map +1 -0
  98. package/dist/vendor/tinbase/storage/image-transform.d.ts +38 -0
  99. package/dist/vendor/tinbase/storage/image-transform.d.ts.map +1 -0
  100. package/dist/vendor/tinbase/storage/s3-driver.d.ts +36 -0
  101. package/dist/vendor/tinbase/storage/s3-driver.d.ts.map +1 -0
  102. package/dist/vendor/tinbase/types.d.ts +171 -0
  103. package/dist/vendor/tinbase/types.d.ts.map +1 -0
  104. package/dist/vendor/tinbase/webhooks/service.d.ts +71 -0
  105. package/dist/vendor/tinbase/webhooks/service.d.ts.map +1 -0
  106. package/dist/version.d.ts +2 -0
  107. package/dist/version.d.ts.map +1 -0
  108. package/package.json +64 -0
@@ -0,0 +1,171 @@
1
+ /**
2
+ * Public configuration and shared types for the tinbase package. {@link BackendConfig}
3
+ * is the primary input to {@link import('./index.js').createBackend}; the rest are
4
+ * the small structural types that config and handlers exchange.
5
+ */
6
+ import type { JwtClaims } from './jwt.js';
7
+ /** A single SQL migration, in Supabase CLI form (one file under supabase/migrations). */
8
+ export interface MigrationFile {
9
+ /** e.g. "20240101120000_create_posts" (no extension) */
10
+ name: string;
11
+ /** Raw SQL applied in one statement batch. */
12
+ sql: string;
13
+ }
14
+ /**
15
+ * Configuration for {@link import('./index.js').createBackend}. Every field is
16
+ * optional; an empty config boots an in-memory PGlite backend on the Supabase
17
+ * local-dev defaults. The CLI derives this object from supabase/config.toml plus
18
+ * the project's migrations/functions/seed.
19
+ */
20
+ export interface BackendConfig {
21
+ /**
22
+ * PGlite data directory. Node: a filesystem path. Browser: "idb://name" or
23
+ * "opfs-ahp://name". Omit for in-memory. Ignored when `engine` is set.
24
+ */
25
+ dataDir?: string;
26
+ /**
27
+ * Custom database engine (e.g. the native embedded Postgres engine from
28
+ * "tinbase/node"). Default: PGlite on `dataDir`.
29
+ */
30
+ engine?: import('./db/engine.js').DbEngine;
31
+ /** Secret used to sign/verify every JWT. Defaults to the Supabase local-dev secret. */
32
+ jwtSecret?: string;
33
+ /**
34
+ * Schemas exposed through the Data API (/rest/v1) for anon/authenticated -
35
+ * PostgREST's db-schemas. Requests profiling into any other schema get a 406
36
+ * unless made with the service_role key. Default: ['public'].
37
+ */
38
+ dbSchemas?: string[];
39
+ /**
40
+ * Auth setting defaults (the committed baseline, e.g. read from
41
+ * supabase/config.toml's [auth] section). Live studio edits, persisted in the
42
+ * auth.config table, are layered on top. Any omitted key falls back to the
43
+ * built-in default.
44
+ */
45
+ authSettings?: Partial<import('./auth/settings.js').AuthSettings>;
46
+ /**
47
+ * Key used to encrypt Vault secrets at rest (pgcrypto). Held only in a session
48
+ * GUC, never stored in the database. Defaults to a value derived from
49
+ * jwtSecret. Required when binding to a network-exposed host (see `host`);
50
+ * always set a dedicated key in production.
51
+ */
52
+ vaultKey?: string;
53
+ /** Public API URL of this backend, used for JWT issuer, OAuth callbacks, email links, and Edge Function env. */
54
+ apiUrl?: string;
55
+ /** Frontend site URL used as the default Auth redirect target. */
56
+ siteUrl?: string;
57
+ /**
58
+ * Host the server is bound to. Used only to decide whether the backend is
59
+ * network-exposed: a non-loopback host turns the default JWT secret and the
60
+ * derived vault key from warnings into hard startup errors. Default: treated
61
+ * as loopback (local dev) when omitted.
62
+ */
63
+ host?: string;
64
+ /** Access token lifetime in seconds (default 3600). */
65
+ jwtExpiry?: number;
66
+ /**
67
+ * Redirect targets allowed beyond the site URL's own origin (GoTrue's
68
+ * URI_ALLOW_LIST). Entries may use `*`/`**` globs. A `redirect_to` matching
69
+ * neither the site origin nor an entry falls back to the site URL.
70
+ */
71
+ uriAllowList?: string[];
72
+ /** Migrations to apply on boot (Supabase CLI convention: sorted by name). */
73
+ migrations?: MigrationFile[];
74
+ /** SQL from supabase/seed.sql, applied once after the first migration run. */
75
+ seedSql?: string;
76
+ /** Where object storage bytes live. Default: in-memory. Node CLI passes a fs driver. */
77
+ storageDriver?: StorageDriver;
78
+ /** Edge functions: name → fetch handler, served at /functions/v1/<name>. */
79
+ functions?: Map<string, import('./functions/handler.js').EdgeFunction> | Record<string, import('./functions/handler.js').EdgeFunction>;
80
+ /** Per-function JWT verification setting from config.toml; false makes the function public. */
81
+ functionVerifyJwt?: Record<string, boolean>;
82
+ /** Extra env/secrets exposed to functions via Deno.env and ctx.env (e.g. from supabase/functions/.env). */
83
+ functionEnv?: Record<string, string>;
84
+ /** Mail transport for OTP/magic-link/recovery emails. Default: console logger. */
85
+ mailer?: Mailer;
86
+ /** OAuth providers, e.g. { google: { clientId, clientSecret } }. Served at /auth/v1/authorize. */
87
+ oauthProviders?: Record<string, import('./auth/oauth.js').OAuthProviderConfig>;
88
+ /** Injectable fetch for OAuth provider calls (tests point this at a mock provider). */
89
+ oauthFetch?: typeof fetch;
90
+ /** Database webhooks: fire HTTP requests on table changes. */
91
+ webhooks?: import('./webhooks/service.js').WebhookConfig[];
92
+ /** Injectable fetch for webhook delivery (tests capture calls). */
93
+ webhookFetch?: typeof fetch;
94
+ /** Injectable fetch for net.http_* (pg_net emulation) delivery (tests capture calls). */
95
+ netFetch?: typeof fetch;
96
+ /** Print startup/debug logs. */
97
+ log?: (msg: string) => void;
98
+ /**
99
+ * Log the full body of auth emails (OTP codes, magic links) to the server log.
100
+ * Off by default so secrets don't land in log files; the /inbox dev UI still
101
+ * shows the full body regardless. Enable only for local debugging.
102
+ */
103
+ logMailBody?: boolean;
104
+ /** Data-retention windows for the background cleanup sweep. */
105
+ retention?: import('./retention/service.js').RetentionConfig;
106
+ /** Max rows a single REST read returns (PostgREST db-max-rows; config.toml api.max_rows). Unlimited if unset. */
107
+ maxRows?: number;
108
+ /** Default per-bucket file size limit in bytes (config.toml storage.file_size_limit). */
109
+ storageFileSizeLimit?: number;
110
+ /** Buckets to create at boot if absent (config.toml storage.buckets.*). */
111
+ buckets?: BucketSeed[];
112
+ /** Force sign-out after this many seconds regardless of activity (config.toml auth.sessions.timebox). */
113
+ sessionTimeboxSeconds?: number;
114
+ /** Sign out after this many seconds of inactivity (config.toml auth.sessions.inactivity_timeout). */
115
+ sessionInactivitySeconds?: number;
116
+ /** Per-endpoint auth rate-limit rules (config.toml auth.rate_limit.*). Defaults applied when unset. */
117
+ authRateLimits?: Record<string, import('./auth/rate-limit.js').RateLimitRule>;
118
+ /** Mount the auth service. Default true; config.toml auth.enabled = false turns /auth/v1 off. */
119
+ authEnabled?: boolean;
120
+ }
121
+ /** A rendered outbound email (OTP code, magic link, recovery, etc.). */
122
+ export interface MailMessage {
123
+ to: string;
124
+ subject: string;
125
+ /** Plain-text body. Carries OTP codes / magic links, so it is not logged by default. */
126
+ text: string;
127
+ }
128
+ /** Pluggable mail transport. Default implementation logs to the console. */
129
+ export interface Mailer {
130
+ send(msg: MailMessage): Promise<void>;
131
+ }
132
+ /**
133
+ * The public Supabase local-dev JWT secret. Used when no `jwtSecret` is set so
134
+ * default keys match a stock `supabase start`.
135
+ *
136
+ * SECURITY: forgeable by anyone (it is public). Startup refuses to bind to a
137
+ * network-exposed host while still using it - see {@link import('./security.js').assertSecretsSafe}.
138
+ */
139
+ export declare const DEFAULT_JWT_SECRET = "";
140
+ /** Per-request execution context derived from apikey/Authorization headers. */
141
+ export interface RequestContext {
142
+ /** Postgres role to SET LOCAL: anon | authenticated | service_role */
143
+ role: string;
144
+ /** Verified JWT claims (published to request.jwt.claims for RLS). */
145
+ claims: JwtClaims | null;
146
+ }
147
+ /** A bucket to create at boot (from config.toml [storage.buckets.<id>]). */
148
+ export interface BucketSeed {
149
+ id: string;
150
+ public: boolean;
151
+ /** Per-bucket byte limit, or null for none. */
152
+ fileSizeLimit: number | null;
153
+ /** Allowed MIME types, or null for any. */
154
+ allowedMimeTypes: string[] | null;
155
+ }
156
+ /** Pluggable object-storage backend for bucket bytes (in-memory, fs, etc.). */
157
+ export interface StorageDriver {
158
+ put(key: string, data: Uint8Array): Promise<void>;
159
+ get(key: string): Promise<Uint8Array | null>;
160
+ delete(key: string): Promise<void>;
161
+ deleteMany(keys: string[]): Promise<void>;
162
+ /** Remote drivers can require cleanup failures to reach the API caller. */
163
+ cleanupFailureMode?: 'ignore' | 'propagate';
164
+ }
165
+ /** Error carrying an HTTP status + JSON body, thrown by handlers and rendered as-is to the client. */
166
+ export declare class ApiError extends Error {
167
+ status: number;
168
+ body: Record<string, unknown>;
169
+ constructor(status: number, body: Record<string, unknown>);
170
+ }
171
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/vendor/tinbase/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEzC,yFAAyF;AACzF,MAAM,WAAW,aAAa;IAC5B,wDAAwD;IACxD,IAAI,EAAE,MAAM,CAAA;IACZ,8CAA8C;IAC9C,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;;;;GAKG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,gBAAgB,EAAE,QAAQ,CAAA;IAC1C,uFAAuF;IACvF,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IACpB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC,OAAO,oBAAoB,EAAE,YAAY,CAAC,CAAA;IACjE;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,gHAAgH;IAChH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,kEAAkE;IAClE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;;OAKG;IACH,IAAI,CAAC,E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AAC,IAAI,CAAC,CAAA;IACjD,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAA;IAC5C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAClC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACzC,2EAA2E;IAC3E,kBAAkB,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAA;CAC5C;AAED,sGAAsG;AACtG,qBAAa,QAAS,SAAQ,KAAK;IAExB,MAAM,EAAE,MAAM;IACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAD7B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAIvC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Database webhooks - fire an HTTP request when rows change, the tinbase
3
+ * equivalent of Supabase Database Webhooks (which use pg_net under the hood).
4
+ * Built on the existing CDC pipeline (triggers + pg_notify), so it needs no C
5
+ * extension and works on both engines. The POST body matches Supabase's
6
+ * webhook payload exactly: { type, table, schema, record, old_record }.
7
+ */
8
+ import type { CdcEvent, Database } from '../db/database.js';
9
+ /** A registered database webhook: which changes to watch and where to POST them. */
10
+ export interface WebhookConfig {
11
+ /** table to watch */
12
+ table: string;
13
+ /** schema of the watched table; defaults to 'public' */
14
+ schema?: string;
15
+ /** which events fire the hook; default all */
16
+ events?: ('INSERT' | 'UPDATE' | 'DELETE')[];
17
+ /** destination URL */
18
+ url: string;
19
+ /** HTTP method (default POST) */
20
+ method?: string;
21
+ /** extra headers (e.g. an auth token) */
22
+ headers?: Record<string, string>;
23
+ /** request timeout ms (default 5000) */
24
+ timeoutMs?: number;
25
+ }
26
+ /** Result of one webhook delivery attempt, passed to the optional `onDelivery` callback. */
27
+ export interface WebhookDelivery {
28
+ webhook: WebhookConfig;
29
+ /** the CDC event that triggered this delivery */
30
+ event: CdcEvent;
31
+ /** HTTP response status; null when the request never got a reply (error/blocked) */
32
+ status: number | null;
33
+ /** true when the response was 2xx */
34
+ ok: boolean;
35
+ /** failure reason (network error, blocked SSRF target); undefined on success */
36
+ error?: string;
37
+ }
38
+ /** Watches the CDC stream and POSTs matching row changes to registered webhooks. */
39
+ export declare class WebhooksService {
40
+ private db;
41
+ private fetchImpl;
42
+ private onDelivery?;
43
+ /**
44
+ * Block delivery to loopback/private/link-local targets (SSRF guard). Off by
45
+ * default so local dev can point a webhook at a local edge function, as
46
+ * `supabase start` does; the backend turns it on when network-exposed.
47
+ */
48
+ private restrictTargets;
49
+ private hooks;
50
+ private stop;
51
+ private started;
52
+ constructor(db: Database, fetchImpl?: typeof fetch, onDelivery?: ((d: WebhookDelivery) => void) | undefined,
53
+ /**
54
+ * Block delivery to loopback/private/link-local targets (SSRF guard). Off by
55
+ * default so local dev can point a webhook at a local edge function, as
56
+ * `supabase start` does; the backend turns it on when network-exposed.
57
+ */
58
+ restrictTargets?: boolean);
59
+ /** All currently registered webhooks. */
60
+ list(): WebhookConfig[];
61
+ /** Register a webhook (ensures the CDC trigger + subscription are live). */
62
+ register(hook: WebhookConfig): Promise<void>;
63
+ /** Register an initial set of webhooks and start dispatching if any exist. */
64
+ start(initial?: WebhookConfig[]): Promise<void>;
65
+ private ensureStarted;
66
+ /** Unsubscribe from the CDC stream; registered hooks are retained. */
67
+ stopService(): void;
68
+ private dispatch;
69
+ private deliver;
70
+ }
71
+ //# sourceMappingURL=service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../src/vendor/tinbase/webhooks/service.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAG3D,oFAAoF;AACpF,MAAM,WAAW,aAAa;IAC5B,qBAAqB;IACrB,KAAK,EAAE,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E,aAAa,EAAO,GAAG,OAAO,CAAC,IAAI,CAAC;YAQ3C,aAAa;IAM3B,sEAAsE;IACtE,WAAW,IAAI,IAAI;IAMnB,OAAO,CAAC,QAAQ;YAUF,OAAO;CAmCtB"}
@@ -0,0 +1,2 @@
1
+ export declare const SUPACLOUD_LITE_VERSION: string;
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,sBAAsB,QAAsB,CAAA"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@supacloud/lite",
3
+ "version": "0.2.0",
4
+ "description": "Bun-native, single-project Supabase-compatible backend powered by PGlite",
5
+ "type": "module",
6
+ "license": "Apache-2.0",
7
+ "bin": {
8
+ "supacloud-lite": "dist/cli.js"
9
+ },
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "README.md",
20
+ "CHANGELOG.md",
21
+ "RELEASING.md",
22
+ "THIRD_PARTY_NOTICES.md",
23
+ "LICENSES"
24
+ ],
25
+ "scripts": {
26
+ "build": "bun run build:js && bun run build:types",
27
+ "build:js": "bun build src/index.ts --target=bun --format=esm --outdir=dist --external @electric-sql/pglite && bun build src/cli.ts --target=bun --format=esm --outdir=dist --external @electric-sql/pglite",
28
+ "build:types": "bun x tsc --emitDeclarationOnly -p tsconfig.build.json",
29
+ "check": "bun run typecheck && bun run test && bun run build && bun run test:package",
30
+ "dev": "bun run src/cli.ts start",
31
+ "start": "bun run src/cli.ts start",
32
+ "test": "bun test --timeout 20000",
33
+ "test:package": "bun run scripts/package-smoke.ts",
34
+ "prepack": "bun run build",
35
+ "typecheck": "bun x tsc --noEmit -p tsconfig.json"
36
+ },
37
+ "dependencies": {
38
+ "@electric-sql/pglite": "0.5.4"
39
+ },
40
+ "devDependencies": {
41
+ "@supabase/supabase-js": "^2.57.4",
42
+ "@types/bun": "^1.3.14",
43
+ "typescript": "^5.9.3"
44
+ },
45
+ "engines": {
46
+ "bun": ">=1.3.14"
47
+ },
48
+ "publishConfig": {
49
+ "access": "public",
50
+ "provenance": true
51
+ },
52
+ "repository": {
53
+ "type": "git",
54
+ "url": "git+https://github.com/zuohuadong/supacloud.git",
55
+ "directory": "packages/supacloud-lite"
56
+ },
57
+ "keywords": [
58
+ "supabase",
59
+ "pglite",
60
+ "bun",
61
+ "postgres",
62
+ "local-first"
63
+ ]
64
+ }