scribase 0.1.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 (162) hide show
  1. package/README.md +220 -0
  2. package/dist/cli/credentials.d.ts +35 -0
  3. package/dist/cli/credentials.d.ts.map +1 -0
  4. package/dist/cli/credentials.js +125 -0
  5. package/dist/cli/credentials.js.map +1 -0
  6. package/dist/cli/envfile.d.ts +20 -0
  7. package/dist/cli/envfile.d.ts.map +1 -0
  8. package/dist/cli/envfile.js +86 -0
  9. package/dist/cli/envfile.js.map +1 -0
  10. package/dist/cli/framework.d.ts +45 -0
  11. package/dist/cli/framework.d.ts.map +1 -0
  12. package/dist/cli/framework.js +107 -0
  13. package/dist/cli/framework.js.map +1 -0
  14. package/dist/cli/index.d.ts +8 -0
  15. package/dist/cli/index.d.ts.map +1 -0
  16. package/dist/cli/index.js +239 -0
  17. package/dist/cli/index.js.map +1 -0
  18. package/dist/cli/init.d.ts +118 -0
  19. package/dist/cli/init.d.ts.map +1 -0
  20. package/dist/cli/init.js +455 -0
  21. package/dist/cli/init.js.map +1 -0
  22. package/dist/cli/login.d.ts +104 -0
  23. package/dist/cli/login.d.ts.map +1 -0
  24. package/dist/cli/login.js +306 -0
  25. package/dist/cli/login.js.map +1 -0
  26. package/dist/cli/pow.d.ts +9 -0
  27. package/dist/cli/pow.d.ts.map +1 -0
  28. package/dist/cli/pow.js +31 -0
  29. package/dist/cli/pow.js.map +1 -0
  30. package/dist/cli/vercel.d.ts +92 -0
  31. package/dist/cli/vercel.d.ts.map +1 -0
  32. package/dist/cli/vercel.js +230 -0
  33. package/dist/cli/vercel.js.map +1 -0
  34. package/dist/client.d.ts +137 -0
  35. package/dist/client.d.ts.map +1 -0
  36. package/dist/client.js +311 -0
  37. package/dist/client.js.map +1 -0
  38. package/dist/errors.d.ts +79 -0
  39. package/dist/errors.d.ts.map +1 -0
  40. package/dist/errors.js +139 -0
  41. package/dist/errors.js.map +1 -0
  42. package/dist/evidence.d.ts +78 -0
  43. package/dist/evidence.d.ts.map +1 -0
  44. package/dist/evidence.js +36 -0
  45. package/dist/evidence.js.map +1 -0
  46. package/dist/idempotency.d.ts +24 -0
  47. package/dist/idempotency.d.ts.map +1 -0
  48. package/dist/idempotency.js +59 -0
  49. package/dist/idempotency.js.map +1 -0
  50. package/dist/importers/firebase.d.ts +101 -0
  51. package/dist/importers/firebase.d.ts.map +1 -0
  52. package/dist/importers/firebase.js +251 -0
  53. package/dist/importers/firebase.js.map +1 -0
  54. package/dist/importers/index.d.ts +11 -0
  55. package/dist/importers/index.d.ts.map +1 -0
  56. package/dist/importers/index.js +9 -0
  57. package/dist/importers/index.js.map +1 -0
  58. package/dist/importers/instantdb.d.ts +76 -0
  59. package/dist/importers/instantdb.d.ts.map +1 -0
  60. package/dist/importers/instantdb.js +152 -0
  61. package/dist/importers/instantdb.js.map +1 -0
  62. package/dist/index.d.ts +78 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +53 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/pagination.d.ts +33 -0
  67. package/dist/pagination.d.ts.map +1 -0
  68. package/dist/pagination.js +68 -0
  69. package/dist/pagination.js.map +1 -0
  70. package/dist/resources/account.d.ts +156 -0
  71. package/dist/resources/account.d.ts.map +1 -0
  72. package/dist/resources/account.js +114 -0
  73. package/dist/resources/account.js.map +1 -0
  74. package/dist/resources/audit.d.ts +26 -0
  75. package/dist/resources/audit.d.ts.map +1 -0
  76. package/dist/resources/audit.js +43 -0
  77. package/dist/resources/audit.js.map +1 -0
  78. package/dist/resources/auth.d.ts +149 -0
  79. package/dist/resources/auth.d.ts.map +1 -0
  80. package/dist/resources/auth.js +70 -0
  81. package/dist/resources/auth.js.map +1 -0
  82. package/dist/resources/backups.d.ts +117 -0
  83. package/dist/resources/backups.d.ts.map +1 -0
  84. package/dist/resources/backups.js +92 -0
  85. package/dist/resources/backups.js.map +1 -0
  86. package/dist/resources/branches.d.ts +151 -0
  87. package/dist/resources/branches.d.ts.map +1 -0
  88. package/dist/resources/branches.js +62 -0
  89. package/dist/resources/branches.js.map +1 -0
  90. package/dist/resources/database.d.ts +107 -0
  91. package/dist/resources/database.d.ts.map +1 -0
  92. package/dist/resources/database.js +54 -0
  93. package/dist/resources/database.js.map +1 -0
  94. package/dist/resources/environments.d.ts +106 -0
  95. package/dist/resources/environments.d.ts.map +1 -0
  96. package/dist/resources/environments.js +131 -0
  97. package/dist/resources/environments.js.map +1 -0
  98. package/dist/resources/export.d.ts +101 -0
  99. package/dist/resources/export.d.ts.map +1 -0
  100. package/dist/resources/export.js +89 -0
  101. package/dist/resources/export.js.map +1 -0
  102. package/dist/resources/functions.d.ts +75 -0
  103. package/dist/resources/functions.d.ts.map +1 -0
  104. package/dist/resources/functions.js +58 -0
  105. package/dist/resources/functions.js.map +1 -0
  106. package/dist/resources/imports.d.ts +183 -0
  107. package/dist/resources/imports.d.ts.map +1 -0
  108. package/dist/resources/imports.js +168 -0
  109. package/dist/resources/imports.js.map +1 -0
  110. package/dist/resources/insights.d.ts +50 -0
  111. package/dist/resources/insights.d.ts.map +1 -0
  112. package/dist/resources/insights.js +21 -0
  113. package/dist/resources/insights.js.map +1 -0
  114. package/dist/resources/metrics.d.ts +61 -0
  115. package/dist/resources/metrics.d.ts.map +1 -0
  116. package/dist/resources/metrics.js +23 -0
  117. package/dist/resources/metrics.js.map +1 -0
  118. package/dist/resources/migrations.d.ts +24 -0
  119. package/dist/resources/migrations.d.ts.map +1 -0
  120. package/dist/resources/migrations.js +29 -0
  121. package/dist/resources/migrations.js.map +1 -0
  122. package/dist/resources/operations.d.ts +37 -0
  123. package/dist/resources/operations.d.ts.map +1 -0
  124. package/dist/resources/operations.js +81 -0
  125. package/dist/resources/operations.js.map +1 -0
  126. package/dist/resources/organizations.d.ts +171 -0
  127. package/dist/resources/organizations.d.ts.map +1 -0
  128. package/dist/resources/organizations.js +180 -0
  129. package/dist/resources/organizations.js.map +1 -0
  130. package/dist/resources/previews.d.ts +49 -0
  131. package/dist/resources/previews.d.ts.map +1 -0
  132. package/dist/resources/previews.js +62 -0
  133. package/dist/resources/previews.js.map +1 -0
  134. package/dist/resources/projects.d.ts +73 -0
  135. package/dist/resources/projects.d.ts.map +1 -0
  136. package/dist/resources/projects.js +84 -0
  137. package/dist/resources/projects.js.map +1 -0
  138. package/dist/resources/queues.d.ts +100 -0
  139. package/dist/resources/queues.d.ts.map +1 -0
  140. package/dist/resources/queues.js +77 -0
  141. package/dist/resources/queues.js.map +1 -0
  142. package/dist/resources/realtime.d.ts +37 -0
  143. package/dist/resources/realtime.d.ts.map +1 -0
  144. package/dist/resources/realtime.js +23 -0
  145. package/dist/resources/realtime.js.map +1 -0
  146. package/dist/resources/restores.d.ts +67 -0
  147. package/dist/resources/restores.d.ts.map +1 -0
  148. package/dist/resources/restores.js +90 -0
  149. package/dist/resources/restores.js.map +1 -0
  150. package/dist/resources/storage.d.ts +50 -0
  151. package/dist/resources/storage.d.ts.map +1 -0
  152. package/dist/resources/storage.js +38 -0
  153. package/dist/resources/storage.js.map +1 -0
  154. package/dist/resources/usage.d.ts +85 -0
  155. package/dist/resources/usage.d.ts.map +1 -0
  156. package/dist/resources/usage.js +37 -0
  157. package/dist/resources/usage.js.map +1 -0
  158. package/dist/types.gen.d.ts +473 -0
  159. package/dist/types.gen.d.ts.map +1 -0
  160. package/dist/types.gen.js +8 -0
  161. package/dist/types.gen.js.map +1 -0
  162. package/package.json +53 -0
@@ -0,0 +1,168 @@
1
+ import { resolveIdempotencyKey } from '../idempotency.js';
2
+ /** Reads the per-table parity from a report, or `[]` when it has none. */
3
+ export function tableParity(report) {
4
+ const verification = report.verification;
5
+ return Array.isArray(verification?.tables) ? verification.tables : [];
6
+ }
7
+ /** Thrown by {@link ImportsResource.wait} when a background import fails. */
8
+ export class ImportFailedError extends Error {
9
+ job;
10
+ constructor(job) {
11
+ const first = job.errors[0];
12
+ super(first
13
+ ? `import ${job.import_id} failed: ${first.detail}`
14
+ : `import ${job.import_id} failed`);
15
+ this.name = 'ImportFailedError';
16
+ this.job = job;
17
+ }
18
+ }
19
+ function sleep(ms, signal) {
20
+ return new Promise((resolve, reject) => {
21
+ if (signal?.aborted) {
22
+ reject(signal.reason ?? new Error('aborted'));
23
+ return;
24
+ }
25
+ const timer = setTimeout(() => {
26
+ signal?.removeEventListener('abort', onAbort);
27
+ resolve();
28
+ }, ms);
29
+ const onAbort = () => {
30
+ clearTimeout(timer);
31
+ reject(signal?.reason ?? new Error('aborted'));
32
+ };
33
+ signal?.addEventListener('abort', onAbort, { once: true });
34
+ });
35
+ }
36
+ /**
37
+ * Imports: migrate a Supabase project, a Firebase export, or an InstantDB
38
+ * export into a Scribase environment, or dry-run the plan first. Everything
39
+ * hits `POST /v1/imports`. A dry run answers with the plan; a full run starts
40
+ * in the background and answers with an {@link ImportJob} whose progress
41
+ * `GET /v1/imports/{id}` reports. Backs
42
+ * `scribase import supabase --project-ref <ref> [--dry-run]`.
43
+ */
44
+ export class ImportsResource {
45
+ #http;
46
+ constructor(http) {
47
+ this.#http = http;
48
+ }
49
+ /**
50
+ * `POST /v1/imports` with `dryRun: false` — start the migration in the
51
+ * background and return its {@link ImportJob} (use {@link wait} or
52
+ * {@link run} to follow it).
53
+ */
54
+ async create(request, options) {
55
+ return this.#start({ ...request, dryRun: false }, options);
56
+ }
57
+ /**
58
+ * `POST /v1/imports` with `dryRun: true` — plan the move and return the
59
+ * {@link ImportDryRun} without writing anything.
60
+ */
61
+ async dryRun(request, options) {
62
+ const result = await this.#http.send({
63
+ method: 'POST',
64
+ path: '/v1/imports',
65
+ body: { ...request, dryRun: true },
66
+ ...(options?.signal ? { signal: options.signal } : {}),
67
+ });
68
+ return result.data;
69
+ }
70
+ /**
71
+ * `POST /v1/imports` for any source — Supabase, Firebase, or InstantDB —
72
+ * started in the background. Returns the {@link ImportJob}.
73
+ */
74
+ async createFrom(request, options) {
75
+ return this.#start({ ...request, dryRun: false }, options);
76
+ }
77
+ /** `POST /v1/imports` for any source with `dryRun: true`. Writes nothing. */
78
+ async dryRunFrom(request, options) {
79
+ const result = await this.#http.send({
80
+ method: 'POST',
81
+ path: '/v1/imports',
82
+ body: { ...request, dryRun: true },
83
+ ...(options?.signal ? { signal: options.signal } : {}),
84
+ });
85
+ return result.data;
86
+ }
87
+ /**
88
+ * `GET /v1/imports/{importId}` — a background run's status, phase, counts
89
+ * moved so far, findings, errors, and (once finished) its report. Pass the
90
+ * organization to read a run the control plane has since restarted past
91
+ * from the import history.
92
+ */
93
+ async progress(importId, options) {
94
+ const result = await this.#http.send({
95
+ method: 'GET',
96
+ path: `/v1/imports/${encodeURIComponent(importId)}`,
97
+ query: { organization_id: options?.organizationId },
98
+ ...(options?.signal ? { signal: options.signal } : {}),
99
+ });
100
+ return result.data;
101
+ }
102
+ /**
103
+ * Polls {@link progress} until the run finishes. Resolves with the final
104
+ * job (its `report` carries the fail-closed `verdict` and, in
105
+ * `verification.tables`, per-table row counts and checksums); rejects with
106
+ * {@link ImportFailedError} when the run failed.
107
+ */
108
+ async wait(importId, options) {
109
+ const interval = Math.max(250, options?.intervalMs ?? 2000);
110
+ for (;;) {
111
+ const job = await this.progress(importId, {
112
+ ...(options?.organizationId ? { organizationId: options.organizationId } : {}),
113
+ ...(options?.signal ? { signal: options.signal } : {}),
114
+ });
115
+ options?.onProgress?.(job);
116
+ if (job.status === 'succeeded') {
117
+ return job;
118
+ }
119
+ if (job.status === 'failed') {
120
+ throw new ImportFailedError(job);
121
+ }
122
+ await sleep(interval, options?.signal);
123
+ }
124
+ }
125
+ /**
126
+ * Starts a run for any source and follows it to the end: the one-call form
127
+ * of {@link createFrom} plus {@link wait}. Resolves with the finished report.
128
+ */
129
+ async run(request, options) {
130
+ const started = await this.createFrom(request, options?.signal ? { signal: options.signal } : {});
131
+ const job = await this.wait(started.import_id, {
132
+ ...options,
133
+ organizationId: request.destination.organizationId,
134
+ });
135
+ if (!job.report) {
136
+ throw new ImportFailedError(job);
137
+ }
138
+ return job.report;
139
+ }
140
+ async #start(body, options) {
141
+ const result = await this.#http.send({
142
+ method: 'POST',
143
+ path: '/v1/imports',
144
+ body,
145
+ idempotencyKey: resolveIdempotencyKey(options?.idempotencyKey),
146
+ ...(options?.signal ? { signal: options.signal } : {}),
147
+ });
148
+ return result.data;
149
+ }
150
+ /** `GET /v1/organizations/{org}/imports` — persisted runs, newest first. */
151
+ async history(organizationId, params) {
152
+ const result = await this.#http.send({
153
+ method: 'GET',
154
+ path: `/v1/organizations/${encodeURIComponent(organizationId)}/imports`,
155
+ query: { limit: params?.limit },
156
+ });
157
+ return result.data.imports;
158
+ }
159
+ /** `GET /v1/organizations/{org}/imports/{importId}` — one run in full. */
160
+ async report(organizationId, importId) {
161
+ const result = await this.#http.send({
162
+ method: 'GET',
163
+ path: `/v1/organizations/${encodeURIComponent(organizationId)}/imports/${encodeURIComponent(importId)}`,
164
+ });
165
+ return result.data;
166
+ }
167
+ }
168
+ //# sourceMappingURL=imports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imports.js","sourceRoot":"","sources":["../../src/resources/imports.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAyG1D,0EAA0E;AAC1E,MAAM,UAAU,WAAW,CAAC,MAAoB;IAC9C,MAAM,YAAY,GAAG,MAAM,CAAC,YAAuD,CAAC;IACpF,OAAO,KAAK,CAAC,OAAO,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC,CAAE,YAAY,CAAC,MAA8B,CAAC,CAAC,CAAC,EAAE,CAAC;AACjG,CAAC;AAsCD,6EAA6E;AAC7E,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,GAAG,CAAY;IAExB,YAAY,GAAc;QACxB,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC5B,KAAK,CACH,KAAK;YACH,CAAC,CAAC,UAAU,GAAG,CAAC,SAAS,YAAY,KAAK,CAAC,MAAM,EAAE;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I,CAAC,OAAO,CAAC;IAC7B,CAAC;IAED,0EAA0E;IAC1E,KAAK,CAAC,MAAM,CACV,cAAkC,EAClC,QAA4B;QAE5B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAe;YACjD,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,qBAAqB,kBAAkB,CAAC,cAAc,CAAC,YAAY,kBAAkB,CACzF,QAAQ,CACT,EAAE;SACJ,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,50 @@
1
+ import type { HttpTransport } from '../client.js';
2
+ import type { EnvironmentRef } from './environments.js';
3
+ /** How much a finding is likely to matter. */
4
+ export type InsightSeverity = 'info' | 'warning' | 'critical';
5
+ /** How sure the analyzer is, given it works from statistics rather than traces. */
6
+ export type InsightConfidence = 'certain' | 'likely' | 'possible';
7
+ /** A change an agent can apply without asking a human to interpret anything. */
8
+ export interface InsightRemediation {
9
+ /** One sentence describing the change. */
10
+ summary: string;
11
+ /** SQL to apply; `null` when the fix is a code change, not a schema change. */
12
+ sql: string | null;
13
+ /** True when applying this can block writes or rewrite a table. */
14
+ requires_review: boolean;
15
+ }
16
+ /**
17
+ * One advisor result: a machine-applicable change plus the query that proves
18
+ * whether it worked.
19
+ */
20
+ export interface InsightFinding {
21
+ /** Stable machine identifier, e.g. `rls.per_row_subquery`. */
22
+ code: string;
23
+ severity: InsightSeverity;
24
+ confidence: InsightConfidence;
25
+ /** Short human title. */
26
+ title: string;
27
+ /** The object this is about, e.g. `public.documents`. */
28
+ subject: string;
29
+ /** Measured facts the finding was derived from. */
30
+ evidence: Record<string, string>;
31
+ remediation: InsightRemediation;
32
+ /** SQL that returns the metric to re-check after applying the remediation. */
33
+ verification: string | null;
34
+ }
35
+ /** The advisor report for an environment: the analyzed findings, worst first. */
36
+ export interface InsightsReport {
37
+ findings: InsightFinding[];
38
+ }
39
+ /**
40
+ * Insights — the read-only workload advisor. It collects the workload from the
41
+ * tenant database and returns machine-actionable findings, each carrying the
42
+ * evidence, remediation SQL, and verification SQL an agent needs.
43
+ */
44
+ export declare class InsightsResource {
45
+ #private;
46
+ constructor(http: HttpTransport);
47
+ /** `GET …/environments/{env}/insights` — the analyzed advisor findings. */
48
+ get(ref: EnvironmentRef): Promise<InsightsReport>;
49
+ }
50
+ //# sourceMappingURL=insights.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insights.d.ts","sourceRoot":"","sources":["../../src/resources/insights.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,8CAA8C;AAC9C,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,CAAC;AAE9D,mFAAmF;AACnF,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,QAAQ,GAAG,UAAU,CAAC;AAElE,gFAAgF;AAChF,MAAM,WAAW,kBAAkB;IACjC,0CAA0C;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,mEAAmE;IACnE,eAAe,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,8DAA8D;IAC9D,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,eAAe,CAAC;IAC1B,UAAU,EAAE,iBAAiB,CAAC;IAC9B,yBAAyB;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,OAAO,EAAE,MAAM,CAAC;IAChB,mDAAmD;IACnD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,WAAW,EAAE,kBAAkB,CAAC;IAChC,8EAA8E;IAC9E,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,iFAAiF;AACjF,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,cAAc,EAAE,CAAC;CAC5B;AAED;;;;GAIG;AACH,qBAAa,gBAAgB;;gBAGf,IAAI,EAAE,aAAa;IAI/B,2EAA2E;IACrE,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,cAAc,CAAC;CAOxD"}
@@ -0,0 +1,21 @@
1
+ import { environmentPath } from './environments.js';
2
+ /**
3
+ * Insights — the read-only workload advisor. It collects the workload from the
4
+ * tenant database and returns machine-actionable findings, each carrying the
5
+ * evidence, remediation SQL, and verification SQL an agent needs.
6
+ */
7
+ export class InsightsResource {
8
+ #http;
9
+ constructor(http) {
10
+ this.#http = http;
11
+ }
12
+ /** `GET …/environments/{env}/insights` — the analyzed advisor findings. */
13
+ async get(ref) {
14
+ const result = await this.#http.send({
15
+ method: 'GET',
16
+ path: `${environmentPath(ref)}/insights`,
17
+ });
18
+ return result.data;
19
+ }
20
+ }
21
+ //# sourceMappingURL=insights.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insights.js","sourceRoot":"","sources":["../../src/resources/insights.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AA4CpD;;;;GAIG;AACH,MAAM,OAAO,gBAAgB;IAClB,KAAK,CAAgB;IAE9B,YAAY,IAAmB;QAC7B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,2EAA2E;IAC3E,KAAK,CAAC,GAAG,CAAC,GAAmB;QAC3B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAiB;YACnD,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,GAAG,eAAe,CAAC,GAAG,CAAC,WAAW;SACzC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,61 @@
1
+ import type { HttpTransport } from '../client.js';
2
+ import type { EnvironmentReference } from '../types.gen.js';
3
+ import type { EnvironmentRef } from './environments.js';
4
+ /** One sample in a metric series. */
5
+ export interface MetricPoint {
6
+ /** Sample time, epoch seconds. */
7
+ epoch_seconds: number;
8
+ /** Measured value at the sample time. */
9
+ value: number;
10
+ }
11
+ /** One named metric and its samples over the reported range. */
12
+ export interface MetricSeries {
13
+ /**
14
+ * Stable metric identifier, e.g. `requests`, `latency_ms`, `errors`,
15
+ * `db_connections`.
16
+ */
17
+ metric: string;
18
+ /** Human-readable unit, e.g. `count` or `ms`. */
19
+ unit: string;
20
+ /** The samples, oldest first. Empty when no sample is available. */
21
+ points: MetricPoint[];
22
+ }
23
+ /**
24
+ * The time range the series cover, in epoch seconds. A single-sample series
25
+ * reports `start === end` and a zero step.
26
+ */
27
+ export interface MetricsRange {
28
+ /** Inclusive range start. */
29
+ start_epoch_seconds: number;
30
+ /** Inclusive range end. */
31
+ end_epoch_seconds: number;
32
+ /** Step between samples; `0` for a single point-in-time snapshot. */
33
+ step_seconds: number;
34
+ }
35
+ /** Response of {@link MetricsResource.get}. */
36
+ export interface MetricsReport {
37
+ /** The environment the metrics belong to. */
38
+ environment: EnvironmentReference;
39
+ /** Where the sample came from, e.g. `postgres` or `unavailable`. */
40
+ source: string;
41
+ /** The time range the series cover. */
42
+ range: MetricsRange;
43
+ /** The metric series, one entry per tracked metric. */
44
+ series: MetricSeries[];
45
+ /** Human-readable note about the sample source or an empty state. */
46
+ notes: string;
47
+ }
48
+ /**
49
+ * Metrics — the read-only operational metrics surface for an environment.
50
+ * Returns a small time-series envelope (request volume, latency, errors, database
51
+ * connections) via the control plane's metrics proxy. The read degrades softly:
52
+ * an unconfigured or unreachable environment yields empty series plus a `notes`
53
+ * string explaining the empty state.
54
+ */
55
+ export declare class MetricsResource {
56
+ #private;
57
+ constructor(http: HttpTransport);
58
+ /** `GET …/environments/{env}/metrics` — recent operational metrics. */
59
+ get(ref: EnvironmentRef): Promise<MetricsReport>;
60
+ }
61
+ //# sourceMappingURL=metrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../src/resources/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,qCAAqC;AACrC,MAAM,WAAW,WAAW;IAC1B,kCAAkC;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,KAAK,EAAE,MAAM,CAAC;CACf;AAED,gEAAgE;AAChE,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAC;IACb,oEAAoE;IACpE,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,6BAA6B;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,2BAA2B;IAC3B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qEAAqE;IACrE,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,+CAA+C;AAC/C,MAAM,WAAW,aAAa;IAC5B,6CAA6C;IAC7C,WAAW,EAAE,oBAAoB,CAAC;IAClC,oEAAoE;IACpE,MAAM,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,KAAK,EAAE,YAAY,CAAC;IACpB,uDAAuD;IACvD,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,qEAAqE;IACrE,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,qBAAa,eAAe;;gBAGd,IAAI,EAAE,aAAa;IAI/B,uEAAuE;IACjE,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;CAOvD"}
@@ -0,0 +1,23 @@
1
+ import { environmentPath } from './environments.js';
2
+ /**
3
+ * Metrics — the read-only operational metrics surface for an environment.
4
+ * Returns a small time-series envelope (request volume, latency, errors, database
5
+ * connections) via the control plane's metrics proxy. The read degrades softly:
6
+ * an unconfigured or unreachable environment yields empty series plus a `notes`
7
+ * string explaining the empty state.
8
+ */
9
+ export class MetricsResource {
10
+ #http;
11
+ constructor(http) {
12
+ this.#http = http;
13
+ }
14
+ /** `GET …/environments/{env}/metrics` — recent operational metrics. */
15
+ async get(ref) {
16
+ const result = await this.#http.send({
17
+ method: 'GET',
18
+ path: `${environmentPath(ref)}/metrics`,
19
+ });
20
+ return result.data;
21
+ }
22
+ }
23
+ //# sourceMappingURL=metrics.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../src/resources/metrics.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAmDpD;;;;;;GAMG;AACH,MAAM,OAAO,eAAe;IACjB,KAAK,CAAgB;IAE9B,YAAY,IAAmB;QAC7B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,uEAAuE;IACvE,KAAK,CAAC,GAAG,CAAC,GAAmB;QAC3B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAgB;YAClD,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,GAAG,eAAe,CAAC,GAAG,CAAC,UAAU;SACxC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,24 @@
1
+ import type { HttpTransport } from '../client.js';
2
+ import type { EnvironmentRef } from './environments.js';
3
+ import type { MigrationInput, RunMigrationsRequest, RunMigrationsResult } from '../types.gen.js';
4
+ export type { MigrationInput, RunMigrationsRequest, RunMigrationsResult, MigrationDirection, MigrationPlanStep, MigrationPlan, MigrationLintSeverity, MigrationLintFinding, } from '../types.gen.js';
5
+ /**
6
+ * Migrations for one environment: plan → lint → apply. A blocking lint finding
7
+ * refuses the migration before a single statement runs. Backs `scribase migrate`.
8
+ */
9
+ export declare class MigrationsResource {
10
+ #private;
11
+ constructor(http: HttpTransport);
12
+ /** `POST …/migrations` — plan, lint, and (when `apply`) run the migrations. */
13
+ run(ref: EnvironmentRef, request: RunMigrationsRequest, options?: {
14
+ signal?: AbortSignal;
15
+ }): Promise<RunMigrationsResult>;
16
+ /**
17
+ * Plan-and-lint only: forces `apply: false` so nothing is executed. Use this
18
+ * to preview the plan and surface blocking findings before committing.
19
+ */
20
+ plan(ref: EnvironmentRef, migrations: MigrationInput[], options?: {
21
+ signal?: AbortSignal;
22
+ }): Promise<RunMigrationsResult>;
23
+ }
24
+ //# sourceMappingURL=migrations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/resources/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,iBAAiB,CAAC;AAKzB,YAAY,EACV,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AAEzB;;;GAGG;AACH,qBAAa,kBAAkB;;gBAGjB,IAAI,EAAE,aAAa;IAI/B,+EAA+E;IACzE,GAAG,CACP,GAAG,EAAE,cAAc,EACnB,OAAO,EAAE,oBAAoB,EAC7B,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GACjC,OAAO,CAAC,mBAAmB,CAAC;IAU/B;;;OAGG;IACG,IAAI,CACR,GAAG,EAAE,cAAc,EACnB,UAAU,EAAE,cAAc,EAAE,EAC5B,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GACjC,OAAO,CAAC,mBAAmB,CAAC;CAGhC"}
@@ -0,0 +1,29 @@
1
+ import { environmentPath } from './environments.js';
2
+ /**
3
+ * Migrations for one environment: plan → lint → apply. A blocking lint finding
4
+ * refuses the migration before a single statement runs. Backs `scribase migrate`.
5
+ */
6
+ export class MigrationsResource {
7
+ #http;
8
+ constructor(http) {
9
+ this.#http = http;
10
+ }
11
+ /** `POST …/migrations` — plan, lint, and (when `apply`) run the migrations. */
12
+ async run(ref, request, options) {
13
+ const result = await this.#http.send({
14
+ method: 'POST',
15
+ path: `${environmentPath(ref)}/migrations`,
16
+ body: request,
17
+ ...(options?.signal ? { signal: options.signal } : {}),
18
+ });
19
+ return result.data;
20
+ }
21
+ /**
22
+ * Plan-and-lint only: forces `apply: false` so nothing is executed. Use this
23
+ * to preview the plan and surface blocking findings before committing.
24
+ */
25
+ async plan(ref, migrations, options) {
26
+ return this.run(ref, { migrations, apply: false }, options);
27
+ }
28
+ }
29
+ //# sourceMappingURL=migrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrations.js","sourceRoot":"","sources":["../../src/resources/migrations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAsBpD;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IACpB,KAAK,CAAgB;IAE9B,YAAY,IAAmB;QAC7B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED,+EAA+E;IAC/E,KAAK,CAAC,GAAG,CACP,GAAmB,EACnB,OAA6B,EAC7B,OAAkC;QAElC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAsB;YACxD,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,GAAG,eAAe,CAAC,GAAG,CAAC,aAAa;YAC1C,IAAI,EAAE,OAAO;YACb,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACvD,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,IAAI,CACR,GAAmB,EACnB,UAA4B,EAC5B,OAAkC;QAElC,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;CACF"}
@@ -0,0 +1,37 @@
1
+ import type { HttpTransport } from '../client.js';
2
+ import type { Operation, OperationState, PortableIdentifier } from '../types.gen.js';
3
+ /** True once an operation can no longer change state. */
4
+ export declare function isTerminal(state: OperationState): boolean;
5
+ export interface WaitOptions {
6
+ /** Poll interval in milliseconds. Default 1000. */
7
+ intervalMs?: number;
8
+ /** Give up after this many milliseconds. Default 300000 (5 min). */
9
+ timeoutMs?: number;
10
+ /** Invoked on every poll with the latest operation snapshot. */
11
+ onUpdate?: (operation: Operation) => void;
12
+ /** Throw {@link OperationFailedError} on failed/cancelled. Default true. */
13
+ throwOnFailure?: boolean;
14
+ /** Caller cancellation for the whole poll loop. */
15
+ signal?: AbortSignal;
16
+ }
17
+ /**
18
+ * Asynchronous operations — the handle every mutation returns. `wait` polls
19
+ * until the operation is terminal, so agents can turn "accepted" into "done"
20
+ * without re-implementing backoff at each call site.
21
+ */
22
+ export declare class OperationsResource {
23
+ #private;
24
+ constructor(http: HttpTransport);
25
+ /**
26
+ * `GET /v1/operations/{id}` — requires the organization scope header
27
+ * (`X-Scribase-Organization-ID`) for membership resolution.
28
+ */
29
+ get(operationId: PortableIdentifier, organizationId: PortableIdentifier): Promise<Operation>;
30
+ /**
31
+ * Poll `get` until the operation reaches a terminal state. Resolves with the
32
+ * terminal {@link Operation}; by default throws {@link OperationFailedError}
33
+ * when it terminates as `failed`/`cancelled`.
34
+ */
35
+ wait(operationId: PortableIdentifier, organizationId: PortableIdentifier, options?: WaitOptions): Promise<Operation>;
36
+ }
37
+ //# sourceMappingURL=operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/resources/operations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAQrF,yDAAyD;AACzD,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAEzD;AAED,MAAM,WAAW,WAAW;IAC1B,mDAAmD;IACnD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oEAAoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gEAAgE;IAChE,QAAQ,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;IAC1C,4EAA4E;IAC5E,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,mDAAmD;IACnD,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;;;GAIG;AACH,qBAAa,kBAAkB;;gBAGjB,IAAI,EAAE,aAAa;IAI/B;;;OAGG;IACG,GAAG,CACP,WAAW,EAAE,kBAAkB,EAC/B,cAAc,EAAE,kBAAkB,GACjC,OAAO,CAAC,SAAS,CAAC;IASrB;;;;OAIG;IACG,IAAI,CACR,WAAW,EAAE,kBAAkB,EAC/B,cAAc,EAAE,kBAAkB,EAClC,OAAO,CAAC,EAAE,WAAW,GACpB,OAAO,CAAC,SAAS,CAAC;CA2BtB"}
@@ -0,0 +1,81 @@
1
+ import { OperationFailedError, PollTimeoutError } from '../errors.js';
2
+ const TERMINAL_STATES = new Set([
3
+ 'succeeded',
4
+ 'failed',
5
+ 'cancelled',
6
+ ]);
7
+ /** True once an operation can no longer change state. */
8
+ export function isTerminal(state) {
9
+ return TERMINAL_STATES.has(state);
10
+ }
11
+ /**
12
+ * Asynchronous operations — the handle every mutation returns. `wait` polls
13
+ * until the operation is terminal, so agents can turn "accepted" into "done"
14
+ * without re-implementing backoff at each call site.
15
+ */
16
+ export class OperationsResource {
17
+ #http;
18
+ constructor(http) {
19
+ this.#http = http;
20
+ }
21
+ /**
22
+ * `GET /v1/operations/{id}` — requires the organization scope header
23
+ * (`X-Scribase-Organization-ID`) for membership resolution.
24
+ */
25
+ async get(operationId, organizationId) {
26
+ const result = await this.#http.send({
27
+ method: 'GET',
28
+ path: `/v1/operations/${encodeURIComponent(operationId)}`,
29
+ organizationHeader: organizationId,
30
+ });
31
+ return result.data;
32
+ }
33
+ /**
34
+ * Poll `get` until the operation reaches a terminal state. Resolves with the
35
+ * terminal {@link Operation}; by default throws {@link OperationFailedError}
36
+ * when it terminates as `failed`/`cancelled`.
37
+ */
38
+ async wait(operationId, organizationId, options) {
39
+ const intervalMs = options?.intervalMs ?? 1000;
40
+ const timeoutMs = options?.timeoutMs ?? 300_000;
41
+ const throwOnFailure = options?.throwOnFailure ?? true;
42
+ const deadline = Date.now() + timeoutMs;
43
+ for (;;) {
44
+ options?.signal?.throwIfAborted();
45
+ const operation = await this.get(operationId, organizationId);
46
+ options?.onUpdate?.(operation);
47
+ if (isTerminal(operation.state)) {
48
+ if (throwOnFailure &&
49
+ (operation.state === 'failed' || operation.state === 'cancelled')) {
50
+ throw new OperationFailedError(operation);
51
+ }
52
+ return operation;
53
+ }
54
+ if (Date.now() + intervalMs > deadline) {
55
+ throw new PollTimeoutError(`operation ${operationId}`, timeoutMs);
56
+ }
57
+ await sleep(intervalMs, options?.signal);
58
+ }
59
+ }
60
+ }
61
+ function sleep(ms, signal) {
62
+ return new Promise((resolve, reject) => {
63
+ const timer = setTimeout(() => {
64
+ signal?.removeEventListener('abort', onAbort);
65
+ resolve();
66
+ }, ms);
67
+ const onAbort = () => {
68
+ clearTimeout(timer);
69
+ reject(signal?.reason ?? new Error('aborted'));
70
+ };
71
+ if (signal) {
72
+ if (signal.aborted) {
73
+ clearTimeout(timer);
74
+ reject(signal.reason ?? new Error('aborted'));
75
+ return;
76
+ }
77
+ signal.addEventListener('abort', onAbort, { once: true });
78
+ }
79
+ });
80
+ }
81
+ //# sourceMappingURL=operations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operations.js","sourceRoot":"","sources":["../../src/resources/operations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGtE,MAAM,eAAe,GAAgC,IAAI,GAAG,CAAiB;IAC3E,WAAW;IACX,QAAQ;IACR,WAAW;CACZ,CAAC,CAAC;AAEH,yDAAyD;AACzD,MAAM,UAAU,UAAU,CAAC,KAAqB;IAC9C,OAAO,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AACpC,CAAC;AAeD;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IACpB,KAAK,CAAgB;IAE9B,YAAY,IAAmB;QAC7B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,GAAG,CACP,WAA+B,EAC/B,cAAkC;QAElC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAY;YAC9C,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,kBAAkB,kBAAkB,CAAC,WAAW,CAAC,EAAE;YACzD,kBAAkB,EAAE,cAAc;SACnC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,IAAI,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,IAAI,CACR,WAA+B,EAC/B,cAAkC,EAClC,OAAqB;QAErB,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,IAAI,CAAC;QAC/C,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,OAAO,CAAC;QAChD,MAAM,cAAc,GAAG,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