@volter/twin-planetscale 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 (128) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +473 -0
  3. package/api/src/fetch.ts +50 -0
  4. package/api/src/generated/surface.gen.json +1 -0
  5. package/api/src/generated/ui.gen.json +1 -0
  6. package/api/src/index.ts +19 -0
  7. package/api/src/manifest.ts +136 -0
  8. package/api/src/screens/deploy-request.tsx +111 -0
  9. package/api/src/screens/service-tokens.tsx +141 -0
  10. package/api/src/screens/session.tsx +117 -0
  11. package/api/src/semantics/audit.ts +82 -0
  12. package/api/src/semantics/backups.ts +258 -0
  13. package/api/src/semantics/branches.ts +201 -0
  14. package/api/src/semantics/deploy-requests.ts +493 -0
  15. package/api/src/semantics/index.ts +371 -0
  16. package/api/src/semantics/shared.ts +141 -0
  17. package/api/src/semantics/time.ts +77 -0
  18. package/api/src/token-gate.ts +96 -0
  19. package/dist/api/src/fetch.d.ts +8 -0
  20. package/dist/api/src/fetch.js +51 -0
  21. package/dist/api/src/fetch.ts +50 -0
  22. package/dist/api/src/generated/surface.gen.json +1 -0
  23. package/dist/api/src/generated/ui.gen.json +1 -0
  24. package/dist/api/src/index.ts +19 -0
  25. package/dist/api/src/manifest.d.ts +2 -0
  26. package/dist/api/src/manifest.js +113 -0
  27. package/dist/api/src/manifest.ts +136 -0
  28. package/dist/api/src/screens/deploy-request.d.ts +7 -0
  29. package/dist/api/src/screens/deploy-request.js +106 -0
  30. package/dist/api/src/screens/deploy-request.tsx +111 -0
  31. package/dist/api/src/screens/service-tokens.d.ts +3 -0
  32. package/dist/api/src/screens/service-tokens.js +134 -0
  33. package/dist/api/src/screens/service-tokens.tsx +141 -0
  34. package/dist/api/src/screens/session.d.ts +11 -0
  35. package/dist/api/src/screens/session.js +108 -0
  36. package/dist/api/src/screens/session.tsx +117 -0
  37. package/dist/api/src/semantics/audit.d.ts +31 -0
  38. package/dist/api/src/semantics/audit.js +80 -0
  39. package/dist/api/src/semantics/audit.ts +82 -0
  40. package/dist/api/src/semantics/backups.d.ts +37 -0
  41. package/dist/api/src/semantics/backups.js +264 -0
  42. package/dist/api/src/semantics/backups.ts +258 -0
  43. package/dist/api/src/semantics/branches.d.ts +53 -0
  44. package/dist/api/src/semantics/branches.js +197 -0
  45. package/dist/api/src/semantics/branches.ts +201 -0
  46. package/dist/api/src/semantics/deploy-requests.d.ts +47 -0
  47. package/dist/api/src/semantics/deploy-requests.js +491 -0
  48. package/dist/api/src/semantics/deploy-requests.ts +493 -0
  49. package/dist/api/src/semantics/index.d.ts +20 -0
  50. package/dist/api/src/semantics/index.js +381 -0
  51. package/dist/api/src/semantics/index.ts +371 -0
  52. package/dist/api/src/semantics/shared.d.ts +36 -0
  53. package/dist/api/src/semantics/shared.js +132 -0
  54. package/dist/api/src/semantics/shared.ts +141 -0
  55. package/dist/api/src/semantics/time.d.ts +2 -0
  56. package/dist/api/src/semantics/time.js +81 -0
  57. package/dist/api/src/semantics/time.ts +77 -0
  58. package/dist/api/src/token-gate.d.ts +9 -0
  59. package/dist/api/src/token-gate.js +97 -0
  60. package/dist/api/src/token-gate.ts +96 -0
  61. package/dist/src/cli.d.ts +2 -0
  62. package/dist/src/cli.js +61 -0
  63. package/dist/src/generated/surface.gen.json +1 -0
  64. package/dist/src/generated/ui.gen.json +1 -0
  65. package/dist/src/index.d.ts +26 -0
  66. package/dist/src/index.js +156 -0
  67. package/dist/src/manifest.d.ts +2 -0
  68. package/dist/src/manifest.js +41 -0
  69. package/dist/src/planetscale-budget.d.ts +78 -0
  70. package/dist/src/planetscale-budget.js +305 -0
  71. package/dist/src/planetscale-capabilities.d.ts +10 -0
  72. package/dist/src/planetscale-capabilities.js +3977 -0
  73. package/dist/src/planetscale-collation-weights.gen.d.ts +4 -0
  74. package/dist/src/planetscale-collation-weights.gen.js +12 -0
  75. package/dist/src/planetscale-collation.d.ts +70 -0
  76. package/dist/src/planetscale-collation.js +391 -0
  77. package/dist/src/planetscale-conformance.d.ts +8 -0
  78. package/dist/src/planetscale-conformance.js +213 -0
  79. package/dist/src/planetscale-connector.d.ts +150 -0
  80. package/dist/src/planetscale-connector.js +532 -0
  81. package/dist/src/planetscale-deploy.d.ts +26 -0
  82. package/dist/src/planetscale-deploy.js +235 -0
  83. package/dist/src/planetscale-information-schema.d.ts +32 -0
  84. package/dist/src/planetscale-information-schema.js +299 -0
  85. package/dist/src/planetscale-mysql.d.ts +33 -0
  86. package/dist/src/planetscale-mysql.js +547 -0
  87. package/dist/src/planetscale-roles.d.ts +11 -0
  88. package/dist/src/planetscale-roles.js +60 -0
  89. package/dist/src/planetscale-row.d.ts +12 -0
  90. package/dist/src/planetscale-row.js +39 -0
  91. package/dist/src/planetscale-server.d.ts +42 -0
  92. package/dist/src/planetscale-server.js +137 -0
  93. package/dist/src/planetscale-sql.d.ts +701 -0
  94. package/dist/src/planetscale-sql.js +7167 -0
  95. package/dist/src/planetscale-store.d.ts +126 -0
  96. package/dist/src/planetscale-store.js +827 -0
  97. package/dist/src/planetscale-twin.d.ts +48 -0
  98. package/dist/src/planetscale-twin.js +290 -0
  99. package/dist/src/planetscale-values.d.ts +139 -0
  100. package/dist/src/planetscale-values.js +719 -0
  101. package/dist/src/planetscale-wire.d.ts +110 -0
  102. package/dist/src/planetscale-wire.js +188 -0
  103. package/dist/src/semantics/psdb.d.ts +18 -0
  104. package/dist/src/semantics/psdb.js +30 -0
  105. package/package.json +58 -0
  106. package/src/cli.ts +58 -0
  107. package/src/generated/surface.gen.json +1 -0
  108. package/src/generated/ui.gen.json +1 -0
  109. package/src/index.ts +267 -0
  110. package/src/manifest.ts +60 -0
  111. package/src/planetscale-budget.ts +347 -0
  112. package/src/planetscale-capabilities.ts +3862 -0
  113. package/src/planetscale-collation-weights.gen.ts +13 -0
  114. package/src/planetscale-collation.ts +378 -0
  115. package/src/planetscale-conformance.ts +237 -0
  116. package/src/planetscale-connector.ts +571 -0
  117. package/src/planetscale-deploy.ts +197 -0
  118. package/src/planetscale-information-schema.ts +322 -0
  119. package/src/planetscale-mysql.ts +339 -0
  120. package/src/planetscale-roles.ts +71 -0
  121. package/src/planetscale-row.ts +43 -0
  122. package/src/planetscale-server.ts +162 -0
  123. package/src/planetscale-sql.ts +5957 -0
  124. package/src/planetscale-store.ts +869 -0
  125. package/src/planetscale-twin.ts +338 -0
  126. package/src/planetscale-values.ts +572 -0
  127. package/src/planetscale-wire.ts +274 -0
  128. package/src/semantics/psdb.ts +57 -0
@@ -0,0 +1,126 @@
1
+ import { SqlError, type Database, type QueryOutcome, type RowRec, type SessionVars, type TableDef, type Write } from './planetscale-sql.js';
2
+ import { type SqlPlan } from './planetscale-deploy.js';
3
+ export declare const SERVICE = "planetscale";
4
+ export declare const PLANETSCALE_RESOURCE_TYPES: readonly ["table", "row", "_session", "_backup", "_branch_table", "_branch_row"];
5
+ export type PlanetscaleResourceType = (typeof PLANETSCALE_RESOURCE_TYPES)[number];
6
+ /** The default schema name a twin branch presents. Overridable per server, like the branch. */
7
+ export declare const DEFAULT_DATABASE = "twin";
8
+ export declare const DEFAULT_BRANCH = "main";
9
+ export type SessionState = {
10
+ id: string;
11
+ inTransaction: boolean;
12
+ /** writes buffered by an open transaction, in order. Empty outside a transaction. */
13
+ pending: Write[];
14
+ pendingPlans: SqlPlan[];
15
+ /** row-lock keys a locking read (`FOR UPDATE`/`FOR SHARE`) took in the open transaction. */
16
+ locks?: string[];
17
+ /** The open transaction is READ ONLY (`START TRANSACTION READ ONLY`, or SET TRANSACTION's). */
18
+ readOnly?: boolean;
19
+ /** `SET SESSION TRANSACTION READ ONLY|READ WRITE`: the access mode of every later transaction. */
20
+ sessionAccess?: 'READ WRITE' | 'READ ONLY';
21
+ /** `SET TRANSACTION READ ONLY|READ WRITE`: the access mode of the NEXT transaction only. */
22
+ nextAccess?: 'READ WRITE' | 'READ ONLY';
23
+ closed: boolean;
24
+ /** the branch scope the session was opened on; absent on `main` */
25
+ scope?: string;
26
+ };
27
+ type Loaded = {
28
+ db: Database;
29
+ /** the sessions of the scope loaded (of `main` when none) */
30
+ sessions: Map<string, SessionState>;
31
+ /** every session id of every scope, which a new session's id must not repeat */
32
+ sessionIds: string[];
33
+ /** subject id → the highest `_rev` ever written for it, INCLUDING deleted subjects. */
34
+ revs: Map<string, number>;
35
+ };
36
+ /** A scope that is `main` (or none) is the World's image; any other names a branch's own subjects. */
37
+ export declare const scopeOf: (database: string, branch: string) => string | undefined;
38
+ /** The action log folded into a `Database` image plus the session book. The maps (tables, rows, sessions) are the
39
+ * caller's own; the row arrays, row records, table definitions and `sessionIds` are shared and must not be changed in
40
+ * place (replace an array to change it, as `applyWritesToImage` does). */
41
+ export declare function loadState(root: string | undefined, databaseName: string, scope?: string): Loaded;
42
+ /** Apply a buffered write list to an in-memory image (the transaction overlay). */
43
+ export declare function applyWritesToImage(db: Database, writes: Write[]): void;
44
+ export type ExecuteContext = {
45
+ root?: string;
46
+ occurredAt: string;
47
+ /** the session variables the client's session carries (planetscale-wire.ts, sessionVarsOf) */
48
+ vars?: SessionVars;
49
+ readOnly?: boolean;
50
+ database?: string;
51
+ branch?: string;
52
+ /** the branch scope the statement acts on (scopeOf); absent on `main` */
53
+ scope?: string;
54
+ };
55
+ export type ExecuteResult = {
56
+ outcome: QueryOutcome;
57
+ /** the session as it stands AFTER the statement — the caller echoes it back on the wire. */
58
+ session: SessionState;
59
+ };
60
+ /** Mint a session id deterministically from the state that already exists — never entropy, never a
61
+ * row count. The serve path must be a pure function of (request, stored state), so a session id is
62
+ * derived from the ids already present rather than from `crypto.randomUUID()`. */
63
+ export declare function mintSessionId(existing: Iterable<string>, occurredAt: string): string;
64
+ /** Open a new session. */
65
+ export declare const createSession: (ctx: ExecuteContext) => Promise<SessionState>;
66
+ /** Close a session, discarding any uncommitted transaction. */
67
+ export declare const closeSession: (ctx: ExecuteContext, id: string) => Promise<boolean>;
68
+ /** Execute ONE statement in the named session. A statement blocked by another transaction's row
69
+ * locks waits OUTSIDE the serialization gate, so the holder's COMMIT can run, then re-executes. */
70
+ export declare function executeSql(ctx: ExecuteContext, sql: string, incomingSessionId: string | null): Promise<ExecuteResult>;
71
+ /**
72
+ * The CURRENT state of one session, or undefined. Read by the request handler's error path: a
73
+ * statement that FAILS inside an open transaction must still echo `inTransaction: true`, because
74
+ * MySQL does not end a transaction on a failed statement (§9 round one, finding 10 — the handler
75
+ * used to answer a flat `false` and tell the caller the transaction had ended when it had not).
76
+ */
77
+ export declare function sessionState(root: string | undefined, id: string, databaseName?: string, scope?: string): SessionState | undefined;
78
+ /** Read-only projection helper — used by the connector's push-free inspection and by tests. */
79
+ export declare function readDatabase(root: string | undefined, databaseName?: string, scope?: string): Database;
80
+ /** The named projections this pack serves through the store door (planetscale-server.ts). */
81
+ export declare const STORE_NAMES: readonly ["tables", "rows"];
82
+ export type StoreName = (typeof STORE_NAMES)[number];
83
+ /**
84
+ * THE STORE DOOR projection (`GET /twin/store/<tables|rows>`, the twin programming model's named
85
+ * read-only read over stored state).
86
+ *
87
+ * The psdb wire is Connect-JSON: EVERY call, `Execute` included, is a POST, and the handler
88
+ * refuses a GET on the RPC path before it authenticates (Connect unary is POST-only, which is
89
+ * vendor-faithful). So a `SELECT` — the vendor's own read — cannot be a GET, and nothing in the
90
+ * vendor surface observes stored state with one. This is that observation: a pure, ordered fold
91
+ * of the same image `Execute` runs against, with the engine's internal `rowid` included because
92
+ * it is the row identity the projection is keyed on.
93
+ *
94
+ * `Map` iteration order is insertion order, which is a function of the log rather than of the
95
+ * state, so both projections are SORTED — by table key, and within a table by rowid.
96
+ */
97
+ export declare function planetscaleStore(name: StoreName, root: string | undefined, databaseName?: string): unknown;
98
+ export { SqlError };
99
+ /** Drop every table of the branch, each in a session of its own that is closed after it: what deleting the database
100
+ * does to its data (the management lane's delete_database; "Remove all data and backups permanently"). */
101
+ export declare function dropAllTables(ctx: ExecuteContext): Promise<void>;
102
+ /** A branch's image as a backup or a new branch carries it: its tables, and its rows by table. */
103
+ export type ScopeImage = {
104
+ tables: TableDef[];
105
+ rows: Array<{
106
+ table: string;
107
+ rows: RowRec[];
108
+ }>;
109
+ };
110
+ /** The image of a scope (`main` when none), sorted as the store door sorts it. */
111
+ export declare function scopeImage(root: string | undefined, scope?: string): ScopeImage;
112
+ /**
113
+ * Make a branch scope hold `image` (its tables, and its rows when a backup is restored): what creating a branch does
114
+ * ("the schema of the source branch is copied to the new branch", planetscale.com/docs/vitess/schema-changes/branching)
115
+ * and what restoring a backup into a new branch does (the spec's `create_branch.backup_id`: "restores the backup's schema
116
+ * and data"). One `branch.seed` action; nothing of `main` is touched.
117
+ */
118
+ export declare function seedScope(ctx: {
119
+ root?: string;
120
+ occurredAt: string;
121
+ }, scope: string, image: ScopeImage): Promise<void>;
122
+ /** Drop every table of a branch scope with its rows, in one action: what deleting the branch does to its data. */
123
+ export declare function dropScope(ctx: {
124
+ root?: string;
125
+ occurredAt: string;
126
+ }, scope: string): Promise<void>;