@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,150 @@
1
+ import type { PerformContext, PushOutcome, RemoteExecute, SyncResource, TwinAction } from '@volter/world-core';
2
+ import { type PlanetscaleBudgetedOptions } from './planetscale-budget.js';
3
+ import { type Cell, type ColumnDef, type TableDef } from './planetscale-sql.js';
4
+ export { pulledRowId, quoteIdent, quoteSqlLiteral } from './planetscale-row.js';
5
+ export type { PlanetscaleBudgetedOptions };
6
+ /**
7
+ * The subset of a real PlanetScale client this connector calls.
8
+ *
9
+ * A `@planetscale/database` `Client`/`Connection` satisfies it structurally. Pulls require
10
+ * execute; a missing executor is a failure, never evidence of an empty database.
11
+ */
12
+ export interface PlanetscaleLikeClient {
13
+ execute?: (query: string, args?: unknown, options?: unknown) => Promise<PlanetscaleExecutedQuery>;
14
+ transaction?: <T>(fn: (tx: unknown) => Promise<T>) => Promise<T>;
15
+ refresh?: () => Promise<void>;
16
+ }
17
+ /** `ExecutedQuery` as the real client returns it (dist/index.d.ts). Only what this connector reads. */
18
+ export type PlanetscaleExecutedQuery = {
19
+ rows: Array<Record<string, unknown>>;
20
+ fields?: Array<{
21
+ name: string;
22
+ type?: string;
23
+ columnType?: string | null;
24
+ flags?: number | null;
25
+ charset?: number | null;
26
+ columnLength?: number | null;
27
+ }>;
28
+ rowsAffected?: number;
29
+ insertId?: string;
30
+ };
31
+ /** One table observed on the real database, already in this twin's storage shape. */
32
+ export type PlanetscaleRealTable = {
33
+ name: string;
34
+ columns: ColumnDef[];
35
+ primaryKey: string[];
36
+ uniques: Array<{
37
+ name: string;
38
+ columns: string[];
39
+ }>;
40
+ autoIncrement: number;
41
+ rows: Array<{
42
+ rowid: number;
43
+ cells: Record<string, Cell>;
44
+ }>;
45
+ };
46
+ /**
47
+ * A `DESCRIBE <table>` row → a `ColumnDef`.
48
+ *
49
+ * MySQL's `DESCRIBE` output is the schema as the SERVER renders it: `Type` is the full column type
50
+ * (`varchar(255)`, `bigint unsigned`), `Null` is `YES`/`NO`, `Key` is `PRI`/`UNI`/`MUL`/``, `Default`
51
+ * is the literal or NULL, and `Extra` carries `auto_increment`. Every field of `ColumnDef` is
52
+ * derivable from those five, which is why the pull needs no information_schema query.
53
+ */
54
+ export declare function mapDescribeRow(row: Record<string, unknown>): ColumnDef;
55
+ /** A real table → the kernel `table` resource. */
56
+ export declare function mapTable(real: PlanetscaleRealTable): SyncResource;
57
+ /** Vendor cells are nested to avoid reserved resource keys. Local write ordinals are
58
+ * deliberately absent: observation must compare vendor facts, not local bookkeeping. */
59
+ export declare function mapRow(table: string, rowid: number, cells: Record<string, Cell>): SyncResource;
60
+ /** Normalize a value the real client handed back into this twin's text-cell encoding. */
61
+ export declare function encodeCellValue(value: unknown): Cell;
62
+ /**
63
+ * MySQL string-literal quoting, for the statements this connector BUILDS.
64
+ *
65
+ * Deliberately a local implementation rather than importing the SDK's `format`: this pack must not
66
+ * depend on the vendor SDK at runtime (it is a devDependency), and the escape set here is the same
67
+ * one `@planetscale/database`'s `dist/sanitization.js` uses — \0 \b \n \r \t \x1a \\ " '.
68
+ */
69
+ /** MySQL identifier quoting — a backtick inside an identifier is doubled. */
70
+ export type PlanetscalePullOptions = {
71
+ /** Only these tables. Omit to discover them with `SHOW TABLES`. */
72
+ tables?: string[];
73
+ /** Maximum returned rows per page (1–10,000), default 500. Not a billed-rows guarantee. */
74
+ rowLimit?: number;
75
+ /** Maximum pages per table (1–100), default 10. A full last page remains partial. */
76
+ maxPages?: number;
77
+ /** Maximum missing-row point checks per refresh (1–1,000), default 100. */
78
+ maxMissingChecks?: number;
79
+ } & PlanetscaleBudgetedOptions;
80
+ export type PlanetscalePullReport = {
81
+ resources: SyncResource[];
82
+ completeTables: string[];
83
+ partialTables: string[];
84
+ };
85
+ export type PlanetscaleRefreshReport = Omit<PlanetscalePullReport, 'resources'> & {
86
+ observed: number;
87
+ deltasAppended: number;
88
+ removed: number;
89
+ };
90
+ /** Discover the real database's table names. */
91
+ export declare function pullPlanetscaleTables(rawClient: PlanetscaleLikeClient, opts?: PlanetscaleBudgetedOptions): Promise<string[]>;
92
+ /** Compatibility resource-only pull. Use pullPlanetscaleSnapshot for completion metadata. */
93
+ export declare function pullPlanetscaleDatabase(rawClient: PlanetscaleLikeClient, opts?: PlanetscalePullOptions): Promise<SyncResource[]>;
94
+ /** Bounded scan. A short page proves that this traversal ended; it is not a global snapshot. */
95
+ export declare function pullPlanetscaleSnapshot(rawClient: PlanetscaleLikeClient, opts?: PlanetscalePullOptions): Promise<PlanetscalePullReport>;
96
+ /**
97
+ * Pull the real database and fold it into the twin through the kernel observation path. Returns `{observed, deltasAppended}` — a re-pull of identical state appends ZERO deltas,
98
+ * which is what makes the pull idempotent.
99
+ */
100
+ export declare function syncPlanetscaleFromReal(rawClient: PlanetscaleLikeClient, opts?: {
101
+ root?: string;
102
+ occurredAt?: string;
103
+ } & PlanetscalePullOptions): Promise<PlanetscaleRefreshReport>;
104
+ /** `now`, forced strictly increasing within this process — see `syncPlanetscaleFromReal`. */
105
+ export declare function pollTimestamp(): string;
106
+ /** Apply captured row changes as one guarded vendor transaction. The transaction reservation
107
+ * covers BEGIN, its callback, COMMIT and rollback, so exhausted budget cannot strand an open
108
+ * transaction halfway through cleanup. Known row plans reserve all row and lifecycle calls. */
109
+ export declare function applyPlanetscaleRows(rawClient: PlanetscaleLikeClient, plan: unknown, opts?: PlanetscaleBudgetedOptions): Promise<string[]>;
110
+ /** Compatibility entry point over the same captured plan as the head's performer. */
111
+ export declare function pushPlanetscaleAction(rawClient: PlanetscaleLikeClient, action: {
112
+ id: string;
113
+ operation?: string;
114
+ subjectType?: string;
115
+ subjectId?: string;
116
+ fields?: Record<string, unknown>;
117
+ input?: Record<string, unknown>;
118
+ }, opts?: {
119
+ root?: string;
120
+ occurredAt?: string;
121
+ } & PlanetscaleBudgetedOptions): Promise<{
122
+ pushed: boolean;
123
+ statement: string;
124
+ }>;
125
+ export declare function pushPlanetscaleActions(rawClient: PlanetscaleLikeClient, opts?: {
126
+ root?: string;
127
+ occurredAt?: string;
128
+ } & PlanetscaleBudgetedOptions): Promise<{
129
+ pushed: number;
130
+ }>;
131
+ export type { TableDef };
132
+ /**
133
+ * A `PlanetscaleLikeClient` over the kernel's executor.
134
+ *
135
+ * PlanetScale's serverless driver speaks CONNECT RPC over unary JSON POSTs to
136
+ * `psdb.v1alpha1.Database` — `CreateSession` then `Execute` — so a session is established once and
137
+ * carried on every query after it, exactly as `@planetscale/database` does. At a REAL boundary the
138
+ * kernel sets the sealed credential over these headers (executor.ts); at the twin's own wire any
139
+ * credential is one.
140
+ */
141
+ export declare function planetscaleClientOver(execute: RemoteExecute): PlanetscaleLikeClient;
142
+ /** The refresh adapter: PlanetScale enumerates through SQL itself (`SHOW TABLES`, then each table),
143
+ * with explicit per-table completion from the bounded scan. */
144
+ export declare function syncPlanetscaleFromRemote(execute: RemoteExecute, opts?: {
145
+ root?: string;
146
+ origin?: string;
147
+ occurredAt?: string;
148
+ } & PlanetscalePullOptions): Promise<PlanetscaleRefreshReport>;
149
+ /** The head performs the captured row plan; query results never become resource fields. */
150
+ export declare function performPlanetscaleAction(execute: RemoteExecute, action: TwinAction, _ctx: PerformContext, opts?: PlanetscaleBudgetedOptions): Promise<PushOutcome>;