@rocicorp/zero 1.4.0-canary.1 → 1.4.0-canary.3

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 (175) hide show
  1. package/out/analyze-query/src/analyze-cli.d.ts +0 -1
  2. package/out/analyze-query/src/analyze-cli.d.ts.map +1 -1
  3. package/out/analyze-query/src/analyze-cli.js +0 -1
  4. package/out/analyze-query/src/analyze-cli.js.map +1 -1
  5. package/out/analyze-query/src/bin-analyze.js +11 -10
  6. package/out/analyze-query/src/bin-analyze.js.map +1 -1
  7. package/out/analyze-query/src/bin-transform.js +1 -1
  8. package/out/analyze-query/src/bin-transform.js.map +1 -1
  9. package/out/replicache/src/btree/node.d.ts +1 -1
  10. package/out/replicache/src/btree/node.d.ts.map +1 -1
  11. package/out/replicache/src/btree/node.js +34 -21
  12. package/out/replicache/src/btree/node.js.map +1 -1
  13. package/out/replicache/src/btree/write.js +1 -2
  14. package/out/replicache/src/btree/write.js.map +1 -1
  15. package/out/replicache/src/kv/sqlite-store.d.ts.map +1 -1
  16. package/out/replicache/src/kv/sqlite-store.js +7 -1
  17. package/out/replicache/src/kv/sqlite-store.js.map +1 -1
  18. package/out/replicache/src/with-transactions.d.ts.map +1 -1
  19. package/out/replicache/src/with-transactions.js +16 -2
  20. package/out/replicache/src/with-transactions.js.map +1 -1
  21. package/out/shared/src/btree-set.d.ts +6 -0
  22. package/out/shared/src/btree-set.d.ts.map +1 -1
  23. package/out/shared/src/btree-set.js +34 -0
  24. package/out/shared/src/btree-set.js.map +1 -1
  25. package/out/zero/package.js +8 -2
  26. package/out/zero/package.js.map +1 -1
  27. package/out/zero/src/adapters/kysely.d.ts +2 -0
  28. package/out/zero/src/adapters/kysely.d.ts.map +1 -0
  29. package/out/zero/src/adapters/kysely.js +2 -0
  30. package/out/zero/src/zero.js +2 -1
  31. package/out/zero-cache/src/auth/write-authorizer.d.ts.map +1 -1
  32. package/out/zero-cache/src/auth/write-authorizer.js +14 -1
  33. package/out/zero-cache/src/auth/write-authorizer.js.map +1 -1
  34. package/out/zero-cache/src/config/zero-config.d.ts +18 -0
  35. package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
  36. package/out/zero-cache/src/config/zero-config.js +35 -3
  37. package/out/zero-cache/src/config/zero-config.js.map +1 -1
  38. package/out/zero-cache/src/db/migration-lite.js +8 -1
  39. package/out/zero-cache/src/db/migration-lite.js.map +1 -1
  40. package/out/zero-cache/src/db/pg-to-lite.d.ts +1 -1
  41. package/out/zero-cache/src/db/pg-to-lite.d.ts.map +1 -1
  42. package/out/zero-cache/src/db/pg-to-lite.js +13 -13
  43. package/out/zero-cache/src/db/pg-to-lite.js.map +1 -1
  44. package/out/zero-cache/src/observability/metrics.d.ts +36 -6
  45. package/out/zero-cache/src/observability/metrics.d.ts.map +1 -1
  46. package/out/zero-cache/src/observability/metrics.js +55 -10
  47. package/out/zero-cache/src/observability/metrics.js.map +1 -1
  48. package/out/zero-cache/src/scripts/decommission.d.ts.map +1 -1
  49. package/out/zero-cache/src/scripts/decommission.js +3 -3
  50. package/out/zero-cache/src/scripts/decommission.js.map +1 -1
  51. package/out/zero-cache/src/scripts/deploy-permissions.js +1 -1
  52. package/out/zero-cache/src/scripts/deploy-permissions.js.map +1 -1
  53. package/out/zero-cache/src/server/change-streamer.d.ts.map +1 -1
  54. package/out/zero-cache/src/server/change-streamer.js +4 -5
  55. package/out/zero-cache/src/server/change-streamer.js.map +1 -1
  56. package/out/zero-cache/src/server/main.d.ts.map +1 -1
  57. package/out/zero-cache/src/server/main.js +6 -1
  58. package/out/zero-cache/src/server/main.js.map +1 -1
  59. package/out/zero-cache/src/server/reaper.d.ts.map +1 -1
  60. package/out/zero-cache/src/server/reaper.js +1 -4
  61. package/out/zero-cache/src/server/reaper.js.map +1 -1
  62. package/out/zero-cache/src/server/shadow-syncer.js +35 -0
  63. package/out/zero-cache/src/server/shadow-syncer.js.map +1 -0
  64. package/out/zero-cache/src/server/syncer.d.ts.map +1 -1
  65. package/out/zero-cache/src/server/syncer.js +2 -8
  66. package/out/zero-cache/src/server/syncer.js.map +1 -1
  67. package/out/zero-cache/src/server/worker-urls.d.ts +1 -0
  68. package/out/zero-cache/src/server/worker-urls.d.ts.map +1 -1
  69. package/out/zero-cache/src/server/worker-urls.js +2 -1
  70. package/out/zero-cache/src/server/worker-urls.js.map +1 -1
  71. package/out/zero-cache/src/services/analyze.d.ts.map +1 -1
  72. package/out/zero-cache/src/services/analyze.js +1 -1
  73. package/out/zero-cache/src/services/analyze.js.map +1 -1
  74. package/out/zero-cache/src/services/change-source/pg/backfill-stream.d.ts +8 -1
  75. package/out/zero-cache/src/services/change-source/pg/backfill-stream.d.ts.map +1 -1
  76. package/out/zero-cache/src/services/change-source/pg/backfill-stream.js +31 -18
  77. package/out/zero-cache/src/services/change-source/pg/backfill-stream.js.map +1 -1
  78. package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
  79. package/out/zero-cache/src/services/change-source/pg/change-source.js +48 -47
  80. package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
  81. package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts +6 -1
  82. package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts.map +1 -1
  83. package/out/zero-cache/src/services/change-source/pg/initial-sync.js +64 -22
  84. package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
  85. package/out/zero-cache/src/services/change-streamer/change-streamer-http.d.ts.map +1 -1
  86. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js +2 -3
  87. package/out/zero-cache/src/services/change-streamer/change-streamer-http.js.map +1 -1
  88. package/out/zero-cache/src/services/change-streamer/schema/tables.js +1 -1
  89. package/out/zero-cache/src/services/replicator/change-processor.d.ts.map +1 -1
  90. package/out/zero-cache/src/services/replicator/change-processor.js +10 -3
  91. package/out/zero-cache/src/services/replicator/change-processor.js.map +1 -1
  92. package/out/zero-cache/src/services/shadow-sync/shadow-sync-service.js +49 -0
  93. package/out/zero-cache/src/services/shadow-sync/shadow-sync-service.js.map +1 -0
  94. package/out/zero-cache/src/services/statz.js +3 -3
  95. package/out/zero-cache/src/services/statz.js.map +1 -1
  96. package/out/zero-cache/src/services/view-syncer/client-handler.js +3 -6
  97. package/out/zero-cache/src/services/view-syncer/client-handler.js.map +1 -1
  98. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts +1 -0
  99. package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
  100. package/out/zero-cache/src/services/view-syncer/cvr-store.js +34 -11
  101. package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
  102. package/out/zero-cache/src/services/view-syncer/cvr.d.ts +16 -1
  103. package/out/zero-cache/src/services/view-syncer/cvr.d.ts.map +1 -1
  104. package/out/zero-cache/src/services/view-syncer/cvr.js +19 -1
  105. package/out/zero-cache/src/services/view-syncer/cvr.js.map +1 -1
  106. package/out/zero-cache/src/services/view-syncer/inspect-handler.js +1 -1
  107. package/out/zero-cache/src/services/view-syncer/inspect-handler.js.map +1 -1
  108. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts +8 -2
  109. package/out/zero-cache/src/services/view-syncer/pipeline-driver.d.ts.map +1 -1
  110. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js +50 -10
  111. package/out/zero-cache/src/services/view-syncer/pipeline-driver.js.map +1 -1
  112. package/out/zero-cache/src/services/view-syncer/row-record-cache.js +4 -7
  113. package/out/zero-cache/src/services/view-syncer/row-record-cache.js.map +1 -1
  114. package/out/zero-cache/src/services/view-syncer/row-set-signature.d.ts +17 -0
  115. package/out/zero-cache/src/services/view-syncer/row-set-signature.d.ts.map +1 -0
  116. package/out/zero-cache/src/services/view-syncer/row-set-signature.js +29 -0
  117. package/out/zero-cache/src/services/view-syncer/row-set-signature.js.map +1 -0
  118. package/out/zero-cache/src/services/view-syncer/schema/cvr.d.ts +1 -0
  119. package/out/zero-cache/src/services/view-syncer/schema/cvr.d.ts.map +1 -1
  120. package/out/zero-cache/src/services/view-syncer/schema/cvr.js +1 -0
  121. package/out/zero-cache/src/services/view-syncer/schema/cvr.js.map +1 -1
  122. package/out/zero-cache/src/services/view-syncer/schema/init.d.ts.map +1 -1
  123. package/out/zero-cache/src/services/view-syncer/schema/init.js +5 -1
  124. package/out/zero-cache/src/services/view-syncer/schema/init.js.map +1 -1
  125. package/out/zero-cache/src/services/view-syncer/schema/types.d.ts +105 -0
  126. package/out/zero-cache/src/services/view-syncer/schema/types.d.ts.map +1 -1
  127. package/out/zero-cache/src/services/view-syncer/schema/types.js +8 -4
  128. package/out/zero-cache/src/services/view-syncer/schema/types.js.map +1 -1
  129. package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
  130. package/out/zero-cache/src/services/view-syncer/view-syncer.js +18 -28
  131. package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
  132. package/out/zero-cache/src/types/pg.d.ts +1 -1
  133. package/out/zero-cache/src/types/pg.d.ts.map +1 -1
  134. package/out/zero-cache/src/types/pg.js +8 -2
  135. package/out/zero-cache/src/types/pg.js.map +1 -1
  136. package/out/zero-cache/src/types/timeout.d.ts +11 -0
  137. package/out/zero-cache/src/types/timeout.d.ts.map +1 -0
  138. package/out/zero-cache/src/types/timeout.js +26 -0
  139. package/out/zero-cache/src/types/timeout.js.map +1 -0
  140. package/out/zero-cache/src/workers/connection.js +3 -3
  141. package/out/zero-cache/src/workers/connection.js.map +1 -1
  142. package/out/zero-client/src/client/version.js +1 -1
  143. package/out/zero-client/src/mod.d.ts +1 -0
  144. package/out/zero-client/src/mod.d.ts.map +1 -1
  145. package/out/zero-client/src/mod.js +1 -0
  146. package/out/zero-react/src/zero.js +1 -0
  147. package/out/zero-server/src/adapters/kysely.d.ts +69 -0
  148. package/out/zero-server/src/adapters/kysely.d.ts.map +1 -0
  149. package/out/zero-server/src/adapters/kysely.js +82 -0
  150. package/out/zero-server/src/adapters/kysely.js.map +1 -0
  151. package/out/zero-server/src/adapters/postgresjs.d.ts.map +1 -1
  152. package/out/zero-server/src/adapters/postgresjs.js +1 -1
  153. package/out/zero-server/src/adapters/postgresjs.js.map +1 -1
  154. package/out/zero-solid/src/zero.js +1 -0
  155. package/out/zql/src/ivm/memory-source.d.ts.map +1 -1
  156. package/out/zql/src/ivm/memory-source.js +3 -3
  157. package/out/zql/src/ivm/memory-source.js.map +1 -1
  158. package/out/zql/src/query/query-internals.d.ts.map +1 -1
  159. package/out/zql/src/query/query-internals.js +1 -1
  160. package/out/zql/src/query/query-internals.js.map +1 -1
  161. package/out/zql/src/query/validate-input.d.ts +8 -0
  162. package/out/zql/src/query/validate-input.d.ts.map +1 -1
  163. package/out/zql/src/query/validate-input.js +15 -2
  164. package/out/zql/src/query/validate-input.js.map +1 -1
  165. package/out/zqlite/src/query-builder.js +19 -7
  166. package/out/zqlite/src/query-builder.js.map +1 -1
  167. package/package.json +10 -2
  168. package/out/analyze-query/src/explain-queries.d.ts +0 -4
  169. package/out/analyze-query/src/explain-queries.d.ts.map +0 -1
  170. package/out/analyze-query/src/explain-queries.js +0 -13
  171. package/out/analyze-query/src/explain-queries.js.map +0 -1
  172. package/out/otel/src/test-log-config.d.ts +0 -8
  173. package/out/otel/src/test-log-config.d.ts.map +0 -1
  174. package/out/otel/src/test-log-config.js +0 -12
  175. package/out/otel/src/test-log-config.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"init.js","names":[],"sources":["../../../../../../../zero-cache/src/services/view-syncer/schema/init.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport type {PendingQuery, Row} from 'postgres';\nimport {\n runSchemaMigrations,\n type IncrementalMigrationMap,\n type Migration,\n} from '../../../db/migration.ts';\nimport type {PostgresDB} from '../../../types/pg.ts';\nimport {cvrSchema, type ShardID} from '../../../types/shards.ts';\nimport {createRowsVersionTable, setupCVRTables} from './cvr.ts';\n\nexport async function initViewSyncerSchema(\n log: LogContext,\n db: PostgresDB,\n shard: ShardID,\n): Promise<void> {\n const schema = cvrSchema(shard);\n\n const setupMigration: Migration = {\n migrateSchema: (lc, tx) => setupCVRTables(lc, tx, shard),\n minSafeVersion: 1,\n };\n\n const migrateV1toV2: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`ALTER TABLE ${tx(schema)}.instances ADD \"replicaVersion\" TEXT`;\n },\n };\n\n const migrateV2ToV3: Migration = {\n migrateSchema: async (_, tx) => {\n await tx.unsafe(createRowsVersionTable(shard));\n },\n\n /** Populates the cvr.rowsVersion table with versions from cvr.instances. */\n migrateData: async (lc, tx) => {\n const pending: PendingQuery<Row[]>[] = [];\n for await (const versions of tx<\n {clientGroupID: string; version: string}[]\n >`\n SELECT \"clientGroupID\", \"version\" FROM ${tx(schema)}.instances`.cursor(\n 5000,\n )) {\n for (const version of versions) {\n pending.push(\n tx`INSERT INTO ${tx(schema)}.\"rowsVersion\" ${tx(version)} \n ON CONFLICT (\"clientGroupID\")\n DO UPDATE SET ${tx(version)}`.execute(),\n );\n }\n }\n lc.info?.(`initializing rowsVersion for ${pending.length} cvrs`);\n await Promise.all(pending);\n },\n };\n\n const migrateV3ToV4: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`ALTER TABLE ${tx(schema)}.instances ADD \"owner\" TEXT`;\n await tx`ALTER TABLE ${tx(schema)}.instances ADD \"grantedAt\" TIMESTAMPTZ`;\n },\n };\n\n const migrateV5ToV6: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`\n ALTER TABLE ${tx(schema)}.\"rows\"\n DROP CONSTRAINT fk_rows_client_group`;\n await tx`\n ALTER TABLE ${tx(schema)}.\"rowsVersion\"\n DROP CONSTRAINT fk_rows_version_client_group`;\n },\n };\n\n const migrateV6ToV7: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`ALTER TABLE ${tx(schema)}.desires ADD \"expiresAt\" TIMESTAMPTZ`;\n await tx`ALTER TABLE ${tx(\n schema,\n )}.desires ADD \"inactivatedAt\" TIMESTAMPTZ`;\n await tx`ALTER TABLE ${tx(schema)}.desires ADD \"ttl\" INTERVAL`;\n\n await tx`CREATE INDEX desires_expires_at ON ${tx(\n schema,\n )}.desires (\"expiresAt\")`;\n await tx`CREATE INDEX desires_inactivated_at ON ${tx(\n schema,\n )}.desires (\"inactivatedAt\")`;\n },\n };\n\n const migrateV7ToV8: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`ALTER TABLE ${tx(\n schema,\n )}.\"desires\" DROP CONSTRAINT fk_desires_client`;\n },\n };\n\n const migrateV8ToV9: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`ALTER TABLE ${tx(schema)}.instances ADD \"clientSchema\" JSONB`;\n },\n };\n\n const migrateV9ToV10: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`ALTER TABLE ${tx(schema)}.queries ADD \"queryName\" TEXT`;\n await tx`ALTER TABLE ${tx(schema)}.queries ADD \"queryArgs\" JSONB`;\n await tx`ALTER TABLE ${tx(schema)}.queries ALTER COLUMN \"clientAST\" DROP NOT NULL`;\n },\n };\n\n const migrateV10ToV11: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`DROP INDEX IF EXISTS ${tx(schema)}.desires_expires_at`;\n await tx`ALTER TABLE ${tx(schema)}.desires DROP COLUMN \"expiresAt\"`;\n await tx`DROP INDEX IF EXISTS ${tx(schema)}.client_patch_version`;\n await tx`ALTER TABLE ${tx(schema)}.clients DROP COLUMN \"patchVersion\"`;\n await tx`ALTER TABLE ${tx(schema)}.clients DROP COLUMN \"deleted\"`;\n },\n };\n\n const migratedV11ToV12: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`ALTER TABLE ${tx(schema)}.queries ALTER COLUMN \"queryArgs\" TYPE JSON USING \"queryArgs\"::JSON`;\n },\n };\n\n const migratedV12ToV13: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`ALTER TABLE ${tx(schema)}.instances ADD COLUMN \"ttlClock\" DOUBLE PRECISION NOT NULL DEFAULT 0`;\n },\n };\n\n const migratedV13ToV14: Migration = {\n migrateSchema: async (_, sql) => {\n await sql`\n CREATE INDEX instances_last_active ON ${sql(schema)}.instances (\"lastActive\");\n `;\n\n // Update / add foreign key constraints to cascade deletes.\n for (const [table, reference] of [\n ['clients', 'instances'],\n ['queries', 'instances'],\n ['rows', 'rowsVersion'],\n ] as [string, string][]) {\n const constraint = sql(`fk_${table}_client_group`);\n await sql`\n ALTER TABLE ${sql(schema)}.${sql(table)} DROP CONSTRAINT IF EXISTS ${constraint}`;\n await sql`\n ALTER TABLE ${sql(schema)}.${sql(table)} ADD CONSTRAINT ${constraint}\n FOREIGN KEY(\"clientGroupID\")\n REFERENCES ${sql(schema)}.${sql(reference)} (\"clientGroupID\")\n ON DELETE CASCADE;\n `;\n }\n },\n };\n\n const migratedV14ToV15: Migration = {\n migrateSchema: async (_, sql) => {\n // Add new columns for storing inactivatedAt and ttl in milliseconds.\n // This avoids postgres.js type conversion issues with TIMESTAMPTZ and INTERVAL.\n await sql`ALTER TABLE ${sql(schema)}.desires \n ADD COLUMN \"inactivatedAtMs\" DOUBLE PRECISION`;\n await sql`ALTER TABLE ${sql(schema)}.desires \n ADD COLUMN \"ttlMs\" DOUBLE PRECISION`;\n },\n // Migrate existing data: convert TIMESTAMPTZ to milliseconds for inactivatedAt\n // and INTERVAL to milliseconds for ttl\n // Note: EXTRACT(EPOCH FROM NULL) returns NULL, so NULL values are preserved\n migrateData: async (lc, sql) => {\n lc.info?.(\n 'Migrating desires.inactivatedAt to inactivatedAtMs and ttl to ttlMs',\n );\n await sql`\n UPDATE ${sql(schema)}.desires\n SET \"inactivatedAtMs\" = EXTRACT(EPOCH FROM \"inactivatedAt\") * 1000,\n \"ttlMs\" = EXTRACT(EPOCH FROM \"ttl\") * 1000\n `;\n },\n };\n\n const migratedV15ToV16: Migration = {\n migrateSchema: async (_, sql) => {\n await sql`ALTER TABLE ${sql(schema)}.instances ADD COLUMN \"profileID\" TEXT`;\n await sql`ALTER TABLE ${sql(schema)}.instances ADD COLUMN \"deleted\" BOOL DEFAULT FALSE`;\n\n // Recreate the instances_last_active index to exclude tombstones\n await sql`\n DROP INDEX IF EXISTS ${sql(schema)}.instances_last_active`;\n await sql`\n CREATE INDEX instances_last_active ON ${sql(schema)}.instances (\"lastActive\")\n WHERE NOT \"deleted\"`;\n await sql`\n CREATE INDEX tombstones_last_active ON ${sql(schema)}.instances (\"lastActive\")\n WHERE \"deleted\"`;\n await sql`\n CREATE INDEX profile_ids_last_active ON ${sql(schema)}.instances (\"lastActive\", \"profileID\")\n WHERE \"profileID\" IS NOT NULL`;\n },\n\n // Backfill profileIDs to the `cg${clientGroupID}`, as is done for\n // client groups from old zero-clients that don't send a profileID.\n migrateData: async (lc, sql) => {\n lc.info?.('Backfilling instance.profileIDs');\n await sql`\n UPDATE ${sql(schema)}.instances\n SET \"profileID\" = 'cg' || \"clientGroupID\"\n WHERE \"profileID\" IS NULL\n `;\n },\n };\n\n const schemaVersionMigrationMap: IncrementalMigrationMap = {\n 2: migrateV1toV2,\n 3: migrateV2ToV3,\n 4: migrateV3ToV4,\n // v5 enables asynchronous row-record flushing, and thus relies on\n // the logic that updates and checks the rowsVersion table in v3.\n 5: {minSafeVersion: 3},\n 6: migrateV5ToV6,\n 7: migrateV6ToV7,\n 8: migrateV7ToV8,\n 9: migrateV8ToV9,\n // v10 adds queryName and queryArgs to the queries table to support\n // custom queries. clientAST is now optional to support migrating\n // off client queries.\n 10: migrateV9ToV10,\n // V11 removes the deprecated queries.\"expiresAt\", clients.\"patchVersion\",\n // clients.\"deleted\" columns.\n 11: migrateV10ToV11,\n 12: migratedV11ToV12,\n // V13 adds instances.\"ttlClock\"\n 13: migratedV12ToV13,\n // V14 adds an index on instances.\"lastActive\" and a FK constraint\n // from rows.\"clientGroupID\" to rowsVersion.\"clientGroupID\" for\n // garbage collection\n 14: migratedV13ToV14,\n // V15 adds desires.\"inactivatedAtTTLClock\" to store TTLClock values\n // directly as DOUBLE PRECISION, avoiding postgres.js TIMESTAMPTZ\n // type conversion issues\n 15: migratedV14ToV15,\n // V16 adds instances.\"profileID\" and a corresponding index for estimating\n // active user counts more accurately for apps that use memstore.\n 16: migratedV15ToV16,\n };\n\n await runSchemaMigrations(\n log,\n 'view-syncer',\n cvrSchema(shard),\n db,\n setupMigration,\n schemaVersionMigrationMap,\n );\n}\n"],"mappings":";;;;AAWA,eAAsB,qBACpB,KACA,IACA,OACe;CACf,MAAM,SAAS,UAAU,MAAM;CAE/B,MAAM,iBAA4B;EAChC,gBAAgB,IAAI,OAAO,eAAe,IAAI,IAAI,MAAM;EACxD,gBAAgB;EACjB;CAED,MAAM,gBAA2B,EAC/B,eAAe,OAAO,GAAG,OAAO;AAC9B,QAAM,EAAE,eAAe,GAAG,OAAO,CAAC;IAErC;CAED,MAAM,gBAA2B;EAC/B,eAAe,OAAO,GAAG,OAAO;AAC9B,SAAM,GAAG,OAAO,uBAAuB,MAAM,CAAC;;EAIhD,aAAa,OAAO,IAAI,OAAO;GAC7B,MAAM,UAAiC,EAAE;AACzC,cAAW,MAAM,YAAY,EAE5B;+CACwC,GAAG,OAAO,CAAC,YAAY,OAC9D,IACD,CACC,MAAK,MAAM,WAAW,SACpB,SAAQ,KACN,EAAE,eAAe,GAAG,OAAO,CAAC,iBAAiB,GAAG,QAAQ,CAAC;;+BAEtC,GAAG,QAAQ,GAAG,SAAS,CAC3C;AAGL,MAAG,OAAO,gCAAgC,QAAQ,OAAO,OAAO;AAChE,SAAM,QAAQ,IAAI,QAAQ;;EAE7B;CAED,MAAM,gBAA2B,EAC/B,eAAe,OAAO,GAAG,OAAO;AAC9B,QAAM,EAAE,eAAe,GAAG,OAAO,CAAC;AAClC,QAAM,EAAE,eAAe,GAAG,OAAO,CAAC;IAErC;CAED,MAAM,gBAA2B,EAC/B,eAAe,OAAO,GAAG,OAAO;AAC9B,QAAM,EAAE;oBACM,GAAG,OAAO,CAAC;;AAEzB,QAAM,EAAE;oBACM,GAAG,OAAO,CAAC;;IAG5B;CAED,MAAM,gBAA2B,EAC/B,eAAe,OAAO,GAAG,OAAO;AAC9B,Q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ACJ,KACA,eACA,UAAU,MAAM,EAChB,IACA,gBACA,0BACD"}
1
+ {"version":3,"file":"init.js","names":[],"sources":["../../../../../../../zero-cache/src/services/view-syncer/schema/init.ts"],"sourcesContent":["import type {LogContext} from '@rocicorp/logger';\nimport type {PendingQuery, Row} from 'postgres';\nimport {\n runSchemaMigrations,\n type IncrementalMigrationMap,\n type Migration,\n} from '../../../db/migration.ts';\nimport type {PostgresDB} from '../../../types/pg.ts';\nimport {cvrSchema, type ShardID} from '../../../types/shards.ts';\nimport {createRowsVersionTable, setupCVRTables} from './cvr.ts';\n\nexport async function initViewSyncerSchema(\n log: LogContext,\n db: PostgresDB,\n shard: ShardID,\n): Promise<void> {\n const schema = cvrSchema(shard);\n\n const setupMigration: Migration = {\n migrateSchema: (lc, tx) => setupCVRTables(lc, tx, shard),\n minSafeVersion: 1,\n };\n\n const migrateV1toV2: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`ALTER TABLE ${tx(schema)}.instances ADD \"replicaVersion\" TEXT`;\n },\n };\n\n const migrateV2ToV3: Migration = {\n migrateSchema: async (_, tx) => {\n await tx.unsafe(createRowsVersionTable(shard));\n },\n\n /** Populates the cvr.rowsVersion table with versions from cvr.instances. */\n migrateData: async (lc, tx) => {\n const pending: PendingQuery<Row[]>[] = [];\n for await (const versions of tx<\n {clientGroupID: string; version: string}[]\n >`\n SELECT \"clientGroupID\", \"version\" FROM ${tx(schema)}.instances`.cursor(\n 5000,\n )) {\n for (const version of versions) {\n pending.push(\n tx`INSERT INTO ${tx(schema)}.\"rowsVersion\" ${tx(version)} \n ON CONFLICT (\"clientGroupID\")\n DO UPDATE SET ${tx(version)}`.execute(),\n );\n }\n }\n lc.info?.(`initializing rowsVersion for ${pending.length} cvrs`);\n await Promise.all(pending);\n },\n };\n\n const migrateV3ToV4: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`ALTER TABLE ${tx(schema)}.instances ADD \"owner\" TEXT`;\n await tx`ALTER TABLE ${tx(schema)}.instances ADD \"grantedAt\" TIMESTAMPTZ`;\n },\n };\n\n const migrateV5ToV6: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`\n ALTER TABLE ${tx(schema)}.\"rows\"\n DROP CONSTRAINT fk_rows_client_group`;\n await tx`\n ALTER TABLE ${tx(schema)}.\"rowsVersion\"\n DROP CONSTRAINT fk_rows_version_client_group`;\n },\n };\n\n const migrateV6ToV7: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`ALTER TABLE ${tx(schema)}.desires ADD \"expiresAt\" TIMESTAMPTZ`;\n await tx`ALTER TABLE ${tx(\n schema,\n )}.desires ADD \"inactivatedAt\" TIMESTAMPTZ`;\n await tx`ALTER TABLE ${tx(schema)}.desires ADD \"ttl\" INTERVAL`;\n\n await tx`CREATE INDEX desires_expires_at ON ${tx(\n schema,\n )}.desires (\"expiresAt\")`;\n await tx`CREATE INDEX desires_inactivated_at ON ${tx(\n schema,\n )}.desires (\"inactivatedAt\")`;\n },\n };\n\n const migrateV7ToV8: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`ALTER TABLE ${tx(\n schema,\n )}.\"desires\" DROP CONSTRAINT fk_desires_client`;\n },\n };\n\n const migrateV8ToV9: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`ALTER TABLE ${tx(schema)}.instances ADD \"clientSchema\" JSONB`;\n },\n };\n\n const migrateV9ToV10: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`ALTER TABLE ${tx(schema)}.queries ADD \"queryName\" TEXT`;\n await tx`ALTER TABLE ${tx(schema)}.queries ADD \"queryArgs\" JSONB`;\n await tx`ALTER TABLE ${tx(schema)}.queries ALTER COLUMN \"clientAST\" DROP NOT NULL`;\n },\n };\n\n const migrateV10ToV11: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`DROP INDEX IF EXISTS ${tx(schema)}.desires_expires_at`;\n await tx`ALTER TABLE ${tx(schema)}.desires DROP COLUMN \"expiresAt\"`;\n await tx`DROP INDEX IF EXISTS ${tx(schema)}.client_patch_version`;\n await tx`ALTER TABLE ${tx(schema)}.clients DROP COLUMN \"patchVersion\"`;\n await tx`ALTER TABLE ${tx(schema)}.clients DROP COLUMN \"deleted\"`;\n },\n };\n\n const migratedV11ToV12: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`ALTER TABLE ${tx(schema)}.queries ALTER COLUMN \"queryArgs\" TYPE JSON USING \"queryArgs\"::JSON`;\n },\n };\n\n const migratedV12ToV13: Migration = {\n migrateSchema: async (_, tx) => {\n await tx`ALTER TABLE ${tx(schema)}.instances ADD COLUMN \"ttlClock\" DOUBLE PRECISION NOT NULL DEFAULT 0`;\n },\n };\n\n const migratedV13ToV14: Migration = {\n migrateSchema: async (_, sql) => {\n await sql`\n CREATE INDEX instances_last_active ON ${sql(schema)}.instances (\"lastActive\");\n `;\n\n // Update / add foreign key constraints to cascade deletes.\n for (const [table, reference] of [\n ['clients', 'instances'],\n ['queries', 'instances'],\n ['rows', 'rowsVersion'],\n ] as [string, string][]) {\n const constraint = sql(`fk_${table}_client_group`);\n await sql`\n ALTER TABLE ${sql(schema)}.${sql(table)} DROP CONSTRAINT IF EXISTS ${constraint}`;\n await sql`\n ALTER TABLE ${sql(schema)}.${sql(table)} ADD CONSTRAINT ${constraint}\n FOREIGN KEY(\"clientGroupID\")\n REFERENCES ${sql(schema)}.${sql(reference)} (\"clientGroupID\")\n ON DELETE CASCADE;\n `;\n }\n },\n };\n\n const migratedV14ToV15: Migration = {\n migrateSchema: async (_, sql) => {\n // Add new columns for storing inactivatedAt and ttl in milliseconds.\n // This avoids postgres.js type conversion issues with TIMESTAMPTZ and INTERVAL.\n await sql`ALTER TABLE ${sql(schema)}.desires \n ADD COLUMN \"inactivatedAtMs\" DOUBLE PRECISION`;\n await sql`ALTER TABLE ${sql(schema)}.desires \n ADD COLUMN \"ttlMs\" DOUBLE PRECISION`;\n },\n // Migrate existing data: convert TIMESTAMPTZ to milliseconds for inactivatedAt\n // and INTERVAL to milliseconds for ttl\n // Note: EXTRACT(EPOCH FROM NULL) returns NULL, so NULL values are preserved\n migrateData: async (lc, sql) => {\n lc.info?.(\n 'Migrating desires.inactivatedAt to inactivatedAtMs and ttl to ttlMs',\n );\n await sql`\n UPDATE ${sql(schema)}.desires\n SET \"inactivatedAtMs\" = EXTRACT(EPOCH FROM \"inactivatedAt\") * 1000,\n \"ttlMs\" = EXTRACT(EPOCH FROM \"ttl\") * 1000\n `;\n },\n };\n\n const migratedV15ToV16: Migration = {\n migrateSchema: async (_, sql) => {\n await sql`ALTER TABLE ${sql(schema)}.instances ADD COLUMN \"profileID\" TEXT`;\n await sql`ALTER TABLE ${sql(schema)}.instances ADD COLUMN \"deleted\" BOOL DEFAULT FALSE`;\n\n // Recreate the instances_last_active index to exclude tombstones\n await sql`\n DROP INDEX IF EXISTS ${sql(schema)}.instances_last_active`;\n await sql`\n CREATE INDEX instances_last_active ON ${sql(schema)}.instances (\"lastActive\")\n WHERE NOT \"deleted\"`;\n await sql`\n CREATE INDEX tombstones_last_active ON ${sql(schema)}.instances (\"lastActive\")\n WHERE \"deleted\"`;\n await sql`\n CREATE INDEX profile_ids_last_active ON ${sql(schema)}.instances (\"lastActive\", \"profileID\")\n WHERE \"profileID\" IS NOT NULL`;\n },\n\n // Backfill profileIDs to the `cg${clientGroupID}`, as is done for\n // client groups from old zero-clients that don't send a profileID.\n migrateData: async (lc, sql) => {\n lc.info?.('Backfilling instance.profileIDs');\n await sql`\n UPDATE ${sql(schema)}.instances\n SET \"profileID\" = 'cg' || \"clientGroupID\"\n WHERE \"profileID\" IS NULL\n `;\n },\n };\n\n const migratedV16ToV17: Migration = {\n migrateSchema: async (_, sql) => {\n await sql`ALTER TABLE ${sql(schema)}.queries ADD COLUMN \"rowSetSignature\" TEXT`;\n },\n };\n\n const schemaVersionMigrationMap: IncrementalMigrationMap = {\n 2: migrateV1toV2,\n 3: migrateV2ToV3,\n 4: migrateV3ToV4,\n // v5 enables asynchronous row-record flushing, and thus relies on\n // the logic that updates and checks the rowsVersion table in v3.\n 5: {minSafeVersion: 3},\n 6: migrateV5ToV6,\n 7: migrateV6ToV7,\n 8: migrateV7ToV8,\n 9: migrateV8ToV9,\n // v10 adds queryName and queryArgs to the queries table to support\n // custom queries. clientAST is now optional to support migrating\n // off client queries.\n 10: migrateV9ToV10,\n // V11 removes the deprecated queries.\"expiresAt\", clients.\"patchVersion\",\n // clients.\"deleted\" columns.\n 11: migrateV10ToV11,\n 12: migratedV11ToV12,\n // V13 adds instances.\"ttlClock\"\n 13: migratedV12ToV13,\n // V14 adds an index on instances.\"lastActive\" and a FK constraint\n // from rows.\"clientGroupID\" to rowsVersion.\"clientGroupID\" for\n // garbage collection\n 14: migratedV13ToV14,\n // V15 adds desires.\"inactivatedAtTTLClock\" to store TTLClock values\n // directly as DOUBLE PRECISION, avoiding postgres.js TIMESTAMPTZ\n // type conversion issues\n 15: migratedV14ToV15,\n // V16 adds instances.\"profileID\" and a corresponding index for estimating\n // active user counts more accurately for apps that use memstore.\n 16: migratedV15ToV16,\n // V17 adds queries.\"rowSetSignature\" — XOR'd hash of row IDs attached to\n // each query, used to detect drift on re-hydration of queries containing\n // the Cap operator.\n 17: migratedV16ToV17,\n };\n\n await runSchemaMigrations(\n log,\n 'view-syncer',\n cvrSchema(shard),\n db,\n setupMigration,\n schemaVersionMigrationMap,\n );\n}\n"],"mappings":";;;;AAWA,eAAsB,qBACpB,KACA,IACA,OACe;CACf,MAAM,SAAS,UAAU,MAAM;CAE/B,MAAM,iBAA4B;EAChC,gBAAgB,IAAI,OAAO,eAAe,IAAI,IAAI,MAAM;EACxD,gBAAgB;EACjB;CAED,MAAM,gBAA2B,EAC/B,eAAe,OAAO,GAAG,OAAO;AAC9B,QAAM,EAAE,eAAe,GAAG,OAAO,CAAC;IAErC;CAED,MAAM,gBAA2B;EAC/B,eAAe,OAAO,GAAG,OAAO;AAC9B,SAAM,GAAG,OAAO,uBAAuB,MAAM,CAAC;;EAIhD,aAAa,OAAO,IAAI,OAAO;GAC7B,MAAM,UAAiC,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8B;EAClC,eAAe,OAAO,GAAG,QAAQ;AAC/B,SAAM,GAAG,eAAe,IAAI,OAAO,CAAC;AACpC,SAAM,GAAG,eAAe,IAAI,OAAO,CAAC;AAGpC,SAAM,GAAG;+BACgB,IAAI,OAAO,CAAC;AACrC,SAAM,GAAG;gDACiC,IAAI,OAAO,CAAC;;AAEtD,SAAM,GAAG;iDACkC,IAAI,OAAO,CAAC;;AAEvD,SAAM,GAAG;kDACmC,IAAI,OAAO,CAAC;;;EAM1D,aAAa,OAAO,IAAI,QAAQ;AAC9B,MAAG,OAAO,kCAAkC;AAC5C,SAAM,GAAG;iBACE,IAAI,OAAO,CAAC;;;;;EAK1B;CAED,MAAM,mBAA8B,EAClC,eAAe,OAAO,GAAG,QAAQ;AAC/B,QAAM,GAAG,eAAe,IAAI,OAAO,CAAC;IAEvC;CAED,MAAM,4BAAqD;EACzD,GAAG;EACH,GAAG;EACH,GAAG;EAGH,GAAG,EAAC,gBAAgB,GAAE;EACtB,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EAIH,IAAI;EAGJ,IAAI;EACJ,IAAI;EAEJ,IAAI;EAIJ,IAAI;EAIJ,IAAI;EAGJ,IAAI;EAIJ,IAAI;EACL;AAED,OAAM,oBACJ,KACA,eACA,UAAU,MAAM,EAChB,IACA,gBACA,0BACD"}
@@ -82,6 +82,21 @@ export declare const baseQueryRecordSchema: v.ObjectType<{
82
82
  configVersion?: number | undefined;
83
83
  stateVersion: string;
84
84
  }>;
85
+ /**
86
+ * Hex-encoded XOR signature over `h64(JSON.stringify([schema, table, rowKey]))`
87
+ * of every row currently attached to this query. Maintained incrementally by
88
+ * `PipelineDriver` as ADDs / REMOVEs are yielded from the query's pipeline
89
+ * (EDITs no-op), and persisted via `CVRQueryDrivenUpdater.flush` by a
90
+ * signature-provider callback.
91
+ *
92
+ * Used to detect drift on re-hydration of queries containing the `Cap` operator,
93
+ * which intentionally does not impose ordering and thus may pick a different N-row
94
+ * subset on re-execution. Comparing the pre-hydration signature with the post-
95
+ * hydration signature lets us force a `configVersion` bump so the standard CVR-diff
96
+ * machinery emits the reconciling poke. Absent or `'0'` means the signature is
97
+ * empty (no rows currently attached).
98
+ */
99
+ rowSetSignature: v.Optional<string>;
85
100
  }, undefined>;
86
101
  /**
87
102
  * Internal queries track rows in the database for internal use, such as the
@@ -128,6 +143,21 @@ export declare const internalQueryRecordSchema: v.ObjectType<Omit<{
128
143
  configVersion?: number | undefined;
129
144
  stateVersion: string;
130
145
  }>;
146
+ /**
147
+ * Hex-encoded XOR signature over `h64(JSON.stringify([schema, table, rowKey]))`
148
+ * of every row currently attached to this query. Maintained incrementally by
149
+ * `PipelineDriver` as ADDs / REMOVEs are yielded from the query's pipeline
150
+ * (EDITs no-op), and persisted via `CVRQueryDrivenUpdater.flush` by a
151
+ * signature-provider callback.
152
+ *
153
+ * Used to detect drift on re-hydration of queries containing the `Cap` operator,
154
+ * which intentionally does not impose ordering and thus may pick a different N-row
155
+ * subset on re-execution. Comparing the pre-hydration signature with the post-
156
+ * hydration signature lets us force a `configVersion` bump so the standard CVR-diff
157
+ * machinery emits the reconciling poke. Absent or `'0'` means the signature is
158
+ * empty (no rows currently attached).
159
+ */
160
+ rowSetSignature: v.Optional<string>;
131
161
  }, "type" | "ast"> & {
132
162
  type: v.Type<"internal">;
133
163
  ast: v.Type<import("../../../../../zero-protocol/src/ast.ts").AST>;
@@ -172,6 +202,21 @@ export declare const clientQueryRecordSchema: v.ObjectType<Omit<Omit<{
172
202
  configVersion?: number | undefined;
173
203
  stateVersion: string;
174
204
  }>;
205
+ /**
206
+ * Hex-encoded XOR signature over `h64(JSON.stringify([schema, table, rowKey]))`
207
+ * of every row currently attached to this query. Maintained incrementally by
208
+ * `PipelineDriver` as ADDs / REMOVEs are yielded from the query's pipeline
209
+ * (EDITs no-op), and persisted via `CVRQueryDrivenUpdater.flush` by a
210
+ * signature-provider callback.
211
+ *
212
+ * Used to detect drift on re-hydration of queries containing the `Cap` operator,
213
+ * which intentionally does not impose ordering and thus may pick a different N-row
214
+ * subset on re-execution. Comparing the pre-hydration signature with the post-
215
+ * hydration signature lets us force a `configVersion` bump so the standard CVR-diff
216
+ * machinery emits the reconciling poke. Absent or `'0'` means the signature is
217
+ * empty (no rows currently attached).
218
+ */
219
+ rowSetSignature: v.Optional<string>;
175
220
  }, "patchVersion" | "clientState"> & {
176
221
  /**
177
222
  * The client state for this query, which includes the inactivatedAt, ttl and
@@ -235,6 +280,21 @@ export declare const customQueryRecordSchema: v.ObjectType<Omit<Omit<{
235
280
  configVersion?: number | undefined;
236
281
  stateVersion: string;
237
282
  }>;
283
+ /**
284
+ * Hex-encoded XOR signature over `h64(JSON.stringify([schema, table, rowKey]))`
285
+ * of every row currently attached to this query. Maintained incrementally by
286
+ * `PipelineDriver` as ADDs / REMOVEs are yielded from the query's pipeline
287
+ * (EDITs no-op), and persisted via `CVRQueryDrivenUpdater.flush` by a
288
+ * signature-provider callback.
289
+ *
290
+ * Used to detect drift on re-hydration of queries containing the `Cap` operator,
291
+ * which intentionally does not impose ordering and thus may pick a different N-row
292
+ * subset on re-execution. Comparing the pre-hydration signature with the post-
293
+ * hydration signature lets us force a `configVersion` bump so the standard CVR-diff
294
+ * machinery emits the reconciling poke. Absent or `'0'` means the signature is
295
+ * empty (no rows currently attached).
296
+ */
297
+ rowSetSignature: v.Optional<string>;
238
298
  }, "patchVersion" | "clientState"> & {
239
299
  /**
240
300
  * The client state for this query, which includes the inactivatedAt, ttl and
@@ -298,6 +358,21 @@ export declare const queryRecordSchema: v.UnionType<[v.ObjectType<Omit<Omit<{
298
358
  configVersion?: number | undefined;
299
359
  stateVersion: string;
300
360
  }>;
361
+ /**
362
+ * Hex-encoded XOR signature over `h64(JSON.stringify([schema, table, rowKey]))`
363
+ * of every row currently attached to this query. Maintained incrementally by
364
+ * `PipelineDriver` as ADDs / REMOVEs are yielded from the query's pipeline
365
+ * (EDITs no-op), and persisted via `CVRQueryDrivenUpdater.flush` by a
366
+ * signature-provider callback.
367
+ *
368
+ * Used to detect drift on re-hydration of queries containing the `Cap` operator,
369
+ * which intentionally does not impose ordering and thus may pick a different N-row
370
+ * subset on re-execution. Comparing the pre-hydration signature with the post-
371
+ * hydration signature lets us force a `configVersion` bump so the standard CVR-diff
372
+ * machinery emits the reconciling poke. Absent or `'0'` means the signature is
373
+ * empty (no rows currently attached).
374
+ */
375
+ rowSetSignature: v.Optional<string>;
301
376
  }, "patchVersion" | "clientState"> & {
302
377
  /**
303
378
  * The client state for this query, which includes the inactivatedAt, ttl and
@@ -359,6 +434,21 @@ export declare const queryRecordSchema: v.UnionType<[v.ObjectType<Omit<Omit<{
359
434
  configVersion?: number | undefined;
360
435
  stateVersion: string;
361
436
  }>;
437
+ /**
438
+ * Hex-encoded XOR signature over `h64(JSON.stringify([schema, table, rowKey]))`
439
+ * of every row currently attached to this query. Maintained incrementally by
440
+ * `PipelineDriver` as ADDs / REMOVEs are yielded from the query's pipeline
441
+ * (EDITs no-op), and persisted via `CVRQueryDrivenUpdater.flush` by a
442
+ * signature-provider callback.
443
+ *
444
+ * Used to detect drift on re-hydration of queries containing the `Cap` operator,
445
+ * which intentionally does not impose ordering and thus may pick a different N-row
446
+ * subset on re-execution. Comparing the pre-hydration signature with the post-
447
+ * hydration signature lets us force a `configVersion` bump so the standard CVR-diff
448
+ * machinery emits the reconciling poke. Absent or `'0'` means the signature is
449
+ * empty (no rows currently attached).
450
+ */
451
+ rowSetSignature: v.Optional<string>;
362
452
  }, "patchVersion" | "clientState"> & {
363
453
  /**
364
454
  * The client state for this query, which includes the inactivatedAt, ttl and
@@ -420,6 +510,21 @@ export declare const queryRecordSchema: v.UnionType<[v.ObjectType<Omit<Omit<{
420
510
  configVersion?: number | undefined;
421
511
  stateVersion: string;
422
512
  }>;
513
+ /**
514
+ * Hex-encoded XOR signature over `h64(JSON.stringify([schema, table, rowKey]))`
515
+ * of every row currently attached to this query. Maintained incrementally by
516
+ * `PipelineDriver` as ADDs / REMOVEs are yielded from the query's pipeline
517
+ * (EDITs no-op), and persisted via `CVRQueryDrivenUpdater.flush` by a
518
+ * signature-provider callback.
519
+ *
520
+ * Used to detect drift on re-hydration of queries containing the `Cap` operator,
521
+ * which intentionally does not impose ordering and thus may pick a different N-row
522
+ * subset on re-execution. Comparing the pre-hydration signature with the post-
523
+ * hydration signature lets us force a `configVersion` bump so the standard CVR-diff
524
+ * machinery emits the reconciling poke. Absent or `'0'` means the signature is
525
+ * empty (no rows currently attached).
526
+ */
527
+ rowSetSignature: v.Optional<string>;
423
528
  }, "type" | "ast"> & {
424
529
  type: v.Type<"internal">;
425
530
  ast: v.Type<import("../../../../../zero-protocol/src/ast.ts").AST>;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../../../zero-cache/src/services/view-syncer/schema/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,qCAAqC,CAAC;AAQzD,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAEzC,eAAO,MAAM,gBAAgB;IAC3B;;OAEG;;IAGH;;;;;;;;;;;;;;;OAeG;;aAEH,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAE1D,eAAO,MAAM,iBAAiB,EAAE,UAEtB,CAAC;AAEX,wBAAgB,QAAQ,CAAC,CAAC,EAAE,kBAAkB,GAAG,UAAU,CAO1D;AAED,MAAM,MAAM,kBAAkB,GAAG,UAAU,GAAG,IAAI,CAAC;AAEnD,wBAAgB,WAAW,CACzB,CAAC,EAAE,kBAAkB,EACrB,CAAC,EAAE,kBAAkB,GACpB,MAAM,CAYR;AAED,wBAAgB,UAAU,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,EAAE,UAAU,GAAG,UAAU,CAEpE;AAED,wBAAgB,eAAe,CAAC,CAAC,EAAE,UAAU,GAAG,MAAM,CAErD;AAED,wBAAgB,uBAAuB,CAAC,CAAC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exports.object({
42
42
  var baseQueryRecordSchema = valita_exports.object({
43
43
  id: valita_exports.string(),
44
44
  transformationHash: valita_exports.string().optional(),
45
- transformationVersion: cvrVersionSchema.optional()
45
+ transformationVersion: cvrVersionSchema.optional(),
46
+ rowSetSignature: valita_exports.string().optional()
46
47
  });
47
48
  /**
48
49
  * Internal queries track rows in the database for internal use, such as the
@@ -137,7 +138,8 @@ function queryRecordToQueryRow(clientGroupID, query) {
137
138
  transformationHash: query.transformationHash ?? null,
138
139
  transformationVersion: maybeVersionString(query.transformationVersion),
139
140
  internal: true,
140
- deleted: false
141
+ deleted: false,
142
+ rowSetSignature: query.rowSetSignature ?? null
141
143
  };
142
144
  case "client": return {
143
145
  clientGroupID,
@@ -149,7 +151,8 @@ function queryRecordToQueryRow(clientGroupID, query) {
149
151
  transformationHash: query.transformationHash ?? null,
150
152
  transformationVersion: maybeVersionString(query.transformationVersion),
151
153
  internal: null,
152
- deleted: false
154
+ deleted: false,
155
+ rowSetSignature: query.rowSetSignature ?? null
153
156
  };
154
157
  case "custom": return {
155
158
  clientGroupID,
@@ -161,7 +164,8 @@ function queryRecordToQueryRow(clientGroupID, query) {
161
164
  transformationHash: query.transformationHash ?? null,
162
165
  transformationVersion: maybeVersionString(query.transformationVersion),
163
166
  internal: null,
164
- deleted: false
167
+ deleted: false,
168
+ rowSetSignature: query.rowSetSignature ?? null
165
169
  };
166
170
  }
167
171
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../../../../../zero-cache/src/services/view-syncer/schema/types.ts"],"sourcesContent":["import {jsonValueSchema} from '../../../../../shared/src/bigint-json.ts';\nimport {jsonSchema} from '../../../../../shared/src/json-schema.ts';\nimport * as v from '../../../../../shared/src/valita.ts';\nimport {astSchema} from '../../../../../zero-protocol/src/ast.ts';\nimport {versionFromLexi, versionToLexi} from '../../../types/lexi-version.ts';\nimport {\n majorVersionToString,\n stateVersionFromString,\n} from '../../../types/state-version.ts';\nimport {ttlClockSchema} from '../ttl-clock.ts';\nimport type {QueriesRow} from './cvr.ts';\n\nexport const cvrVersionSchema = v.object({\n /**\n * The database `stateVersion` with which the rows in the CVR are consistent.\n */\n stateVersion: v.string(), // LexiVersion\n\n /**\n * `configVersion` is subversion of `stateVersion` that is initially absent for each\n * `stateVersion`, and incremented for configuration changes that affect the contents\n * of the CVR such as:\n *\n * * query set changes\n * * query transformation changes (which may happen for changes\n * in server-side logic or authorization policies)\n *\n * Such configuration changes are always correlated with a change to one or more\n * `/meta/...` records in the CVR, often (but not always) with corresponding\n * patches in `/patches/meta/...`.\n *\n * When the `stateVersion` moves forward, the `minorVersion` is reset to absent.\n * In this manner it behaves like the analogous concept in semantic versioning.\n */\n configVersion: v.number().optional(),\n});\n\nexport type CVRVersion = v.Infer<typeof cvrVersionSchema>;\n\nexport const EMPTY_CVR_VERSION: CVRVersion = {\n stateVersion: majorVersionToString(0),\n} as const;\n\nexport function oneAfter(v: NullableCVRVersion): CVRVersion {\n return v === null\n ? {stateVersion: majorVersionToString(0)}\n : {\n stateVersion: v.stateVersion,\n configVersion: (v.configVersion ?? 0) + 1,\n };\n}\n\nexport type NullableCVRVersion = CVRVersion | null;\n\nexport function cmpVersions(\n a: NullableCVRVersion,\n b: NullableCVRVersion,\n): number {\n return a === null && b === null\n ? 0\n : a === null\n ? -1\n : b === null\n ? 1\n : a.stateVersion < b.stateVersion\n ? -1\n : a.stateVersion > b.stateVersion\n ? 1\n : (a.configVersion ?? 0) - (b.configVersion ?? 0);\n}\n\nexport function maxVersion(a: CVRVersion, b?: CVRVersion): CVRVersion {\n return !b ? a : cmpVersions(b, a) > 0 ? b : a;\n}\n\nexport function versionToCookie(v: CVRVersion): string {\n return versionString(v);\n}\n\nexport function versionToNullableCookie(v: NullableCVRVersion): string | null {\n return v === null ? null : versionToCookie(v);\n}\n\nexport function cookieToVersion(cookie: string | null): NullableCVRVersion {\n if (cookie === null) {\n return null;\n }\n return versionFromString(cookie);\n}\n\n// Last Active tracking.\n\nexport const cvrIDSchema = v.object({id: v.string()});\nexport type CvrID = v.Infer<typeof cvrIDSchema>;\n\nconst cvrRecordSchema = v.object({\n /**\n * CVR records store the CVRVersion at which the record was last patched into\n * the CVR, which corresponds with a patch row that is cleaned up when the\n * record is changed (updated, deleted, and re-added in the case of rows).\n *\n * Tombstones are stored for row records but not for config records. This means\n * that \"orphaned\" delete patches for config records may exist, and therefore\n * scans of config patches must always run until the end of the list. On the\n * contrary, for row patches, the row record tombstones allow cleanup of delete\n * patches.\n */\n patchVersion: cvrVersionSchema,\n});\n\nexport const clientRecordSchema = v.object({\n /** The client ID, of which there can be multiple for a client group view. */\n id: v.string(),\n\n /** The client's desired query IDs. Patch information is stored in the QueryRecord. */\n desiredQueryIDs: v.array(v.string()),\n});\n\nexport type ClientRecord = v.Infer<typeof clientRecordSchema>;\n\nexport const baseQueryRecordSchema = v.object({\n /** The client-specified ID used to identify this query. Typically a hash. */\n id: v.string(),\n\n /**\n * The hash of the query after server-side transformations, which include:\n *\n * * Normalization (which may differ from what the client does)\n * * Query \"expansion\" to include primary keys and query-execution-related columns\n * * Authorization transforms\n *\n * Transformations depend on conditions that are independent of the db state version,\n * such as server-side logic and authorization policies. As such, the version of a CVR\n * version may need to be advanced independent of db state changes. This is done\n * via the `minorVersion` counter of the CVRVersion object, which is used to account\n * for both changes to the query set and changes to query transformations (which are\n * effectively remove-old-query + add-new-query).\n *\n * Note that the transformed AST itself is **not** stored, as the result of the previous\n * transformation is not useful in and of itself. If the current transformation results in\n * a different hash than that of the transformation used for the last version of the CVR,\n * it is simply handled by invalidating the existing rows, re-executed the query with\n * the new transformation, and advancing the CVR's `minorVersion` and this query's\n * `transformationVersion`.\n *\n * Note that the transformationHash is only stored when the query has reached the \"gotten\"\n * state. If the query is in the \"desired\" but not yet \"gotten\" state, the field is absent.\n */\n transformationHash: v.string().optional(),\n\n /**\n * The CVR version corresponding to the `transformationHash`. This essentially tracks when\n * this version of the query was effectively added to the CVR (as opposed to the\n * `patchVersion`, which is simply when the client was notified that its query was added\n * to the gotten set). Catchup of clients from old CVR versions require executing all\n * queries with a newer `transformationVersion`.\n */\n transformationVersion: cvrVersionSchema.optional(),\n});\n\n/**\n * Internal queries track rows in the database for internal use, such as the\n * `lastMutationID`s in the `zero.clients` table. They participate in the standard\n * invalidation / update logic for row contents, but not in the desired/got or\n * size-based quota logic for client-requested queries.\n */\nexport const internalQueryRecordSchema = baseQueryRecordSchema.extend({\n type: v.literal('internal'),\n ast: astSchema,\n});\n\nexport type InternalQueryRecord = v.Infer<typeof internalQueryRecordSchema>;\n\nconst clientStateSchema = v.object({\n /**\n * The time at which the query was last inactivated. If this undefined or\n * missing then the query is active.\n *\n * Desired queries are always active and have an undefined inactivatedAt.\n */\n inactivatedAt: ttlClockSchema.optional(),\n\n /**\n * TTL, time to live in milliseconds. If the query is not updated within this\n * time. The time to live is the time after it has become inactive. Negative\n * values are treated as `'forever'`.\n *\n * We do clamp this to a maximum of 10 minutes, so that queries do not\n * live for a very long time in the CVR.\n */\n ttl: v.number(),\n\n /**\n * The version at which the client state changed (i.e. individual `patchVersion`s).\n */\n version: cvrVersionSchema,\n});\n\nconst externalQueryRecordSchema = baseQueryRecordSchema.extend({\n /**\n * The client state for this query, which includes the inactivatedAt, ttl and\n * version. The client state is stored in a record with the client ID as the\n * key.\n */\n clientState: v.record(clientStateSchema),\n\n // For queries, the `patchVersion` indicates when query was added to the got set,\n // and is absent if not yet gotten.\n patchVersion: cvrVersionSchema.optional(),\n});\n\nexport const clientQueryRecordSchema = externalQueryRecordSchema.extend({\n type: v.literal('client'),\n\n /** The original AST as supplied by the client. */\n ast: astSchema,\n});\n\nexport type ClientQueryRecord = v.Infer<typeof clientQueryRecordSchema>;\n\nexport const customQueryRecordSchema = externalQueryRecordSchema.extend({\n type: v.literal('custom'),\n name: v.string(),\n args: v.readonly(v.array(jsonSchema)),\n});\n\nexport type CustomQueryRecord = v.Infer<typeof customQueryRecordSchema>;\n\nexport const queryRecordSchema = v.union(\n clientQueryRecordSchema,\n customQueryRecordSchema,\n internalQueryRecordSchema,\n);\n\nexport type QueryRecord = v.Infer<typeof queryRecordSchema>;\n\nexport const rowIDSchema = v.object({\n schema: v.string(),\n table: v.string(),\n rowKey: v.record(jsonValueSchema),\n});\n\nexport type RowID = v.Infer<typeof rowIDSchema>;\n\nexport const rowRecordSchema = cvrRecordSchema.extend({\n id: rowIDSchema,\n rowVersion: v.string(), // '_0_version' of the row\n // query hashes => refCount, or `null` for a row that was removed from the\n // view (i.e. tombstone).\n refCounts: v.record(v.number()).nullable(),\n});\n\nexport type RowRecord = v.Infer<typeof rowRecordSchema>;\n\nexport const patchSchema = v.object({\n type: v.literalUnion('row', 'query'),\n op: v.literalUnion('put', 'del'),\n});\n\nexport const putRowPatchSchema = patchSchema.extend({\n type: v.literal('row'),\n op: v.literal('put'),\n id: rowIDSchema,\n rowVersion: v.string(), // '_0_version' of the row\n});\n\nexport type PutRowPatch = v.Infer<typeof putRowPatchSchema>;\n\nexport const delRowPatchSchema = patchSchema.extend({\n type: v.literal('row'),\n op: v.literal('del'),\n id: rowIDSchema,\n});\n\nexport type DelRowPatch = v.Infer<typeof delRowPatchSchema>;\n\nexport const rowPatchSchema = v.union(putRowPatchSchema, delRowPatchSchema);\n\nexport type RowPatch = v.Infer<typeof rowPatchSchema>;\n\nexport const queryPatchSchema = patchSchema.extend({\n type: v.literal('query'),\n id: v.string(),\n clientID: v.string().optional(), // defined for \"desired\", undefined for \"got\"\n});\n\nexport type QueryPatch = v.Infer<typeof queryPatchSchema>;\n\nexport type PutQueryPatch = QueryPatch & {op: 'put'};\nexport type DelQueryPatch = QueryPatch & {op: 'del'};\n\nexport const metadataPatchSchema = queryPatchSchema;\n\nexport type MetadataPatch = v.Infer<typeof metadataPatchSchema>;\n\nexport function versionString(v: CVRVersion) {\n // The separator (e.g. \":\") needs to be lexicographically greater than the\n // storage key path separator (e.g. \"/\") so that \"01/row-hash\" is less than \"01:01/row-hash\".\n // In particular, the traditional separator for major.minor versions (\".\") does not\n // satisfy this quality.\n return v.configVersion\n ? `${v.stateVersion}:${versionToLexi(v.configVersion)}`\n : v.stateVersion;\n}\n\nexport function versionFromString(str: string): CVRVersion {\n const parts = str.split(':');\n const stateVersion = parts[0];\n switch (parts.length) {\n case 1: {\n stateVersionFromString(stateVersion); // Purely for validation.\n return {stateVersion};\n }\n case 2: {\n const configVersion = versionFromLexi(parts[1]);\n if (configVersion > BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new Error(`minorVersion ${parts[1]} exceeds max safe integer`);\n }\n return {stateVersion, configVersion: Number(configVersion)};\n }\n default:\n throw new TypeError(`Invalid version string ${str}`);\n }\n}\n\nexport function queryRecordToQueryRow(\n clientGroupID: string,\n query: QueryRecord,\n): QueriesRow {\n switch (query.type) {\n case 'internal':\n return {\n clientGroupID,\n queryHash: query.id,\n clientAST: query.ast,\n queryName: null,\n queryArgs: null,\n patchVersion: null,\n transformationHash: query.transformationHash ?? null,\n transformationVersion: maybeVersionString(query.transformationVersion),\n internal: true,\n deleted: false, // put vs del \"got\" query\n };\n case 'client':\n return {\n clientGroupID,\n queryHash: query.id,\n clientAST: query.ast,\n queryName: null,\n queryArgs: null,\n patchVersion: maybeVersionString(query.patchVersion),\n transformationHash: query.transformationHash ?? null,\n transformationVersion: maybeVersionString(query.transformationVersion),\n internal: null,\n deleted: false, // put vs del \"got\" query\n };\n case 'custom':\n return {\n clientGroupID,\n queryHash: query.id,\n clientAST: null,\n queryName: query.name,\n queryArgs: query.args,\n patchVersion: maybeVersionString(query.patchVersion),\n transformationHash: query.transformationHash ?? null,\n transformationVersion: maybeVersionString(query.transformationVersion),\n internal: null,\n deleted: false, // put vs del \"got\" query\n };\n }\n}\n\nexport const maybeVersionString = (v: CVRVersion | undefined) =>\n v ? versionString(v) : null;\n"],"mappings":";;;;;;;;AAYA,IAAa,mBAAmB,eAAE,OAAO;CAIvC,cAAc,eAAE,QAAQ;CAkBxB,eAAe,eAAE,QAAQ,CAAC,UAAU;CACrC,CAAC;A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}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../../../../../zero-cache/src/services/view-syncer/schema/types.ts"],"sourcesContent":["import {jsonValueSchema} from '../../../../../shared/src/bigint-json.ts';\nimport {jsonSchema} from '../../../../../shared/src/json-schema.ts';\nimport * as v from '../../../../../shared/src/valita.ts';\nimport {astSchema} from '../../../../../zero-protocol/src/ast.ts';\nimport {versionFromLexi, versionToLexi} from '../../../types/lexi-version.ts';\nimport {\n majorVersionToString,\n stateVersionFromString,\n} from '../../../types/state-version.ts';\nimport {ttlClockSchema} from '../ttl-clock.ts';\nimport type {QueriesRow} from './cvr.ts';\n\nexport const cvrVersionSchema = v.object({\n /**\n * The database `stateVersion` with which the rows in the CVR are consistent.\n */\n stateVersion: v.string(), // LexiVersion\n\n /**\n * `configVersion` is subversion of `stateVersion` that is initially absent for each\n * `stateVersion`, and incremented for configuration changes that affect the contents\n * of the CVR such as:\n *\n * * query set changes\n * * query transformation changes (which may happen for changes\n * in server-side logic or authorization policies)\n *\n * Such configuration changes are always correlated with a change to one or more\n * `/meta/...` records in the CVR, often (but not always) with corresponding\n * patches in `/patches/meta/...`.\n *\n * When the `stateVersion` moves forward, the `minorVersion` is reset to absent.\n * In this manner it behaves like the analogous concept in semantic versioning.\n */\n configVersion: v.number().optional(),\n});\n\nexport type CVRVersion = v.Infer<typeof cvrVersionSchema>;\n\nexport const EMPTY_CVR_VERSION: CVRVersion = {\n stateVersion: majorVersionToString(0),\n} as const;\n\nexport function oneAfter(v: NullableCVRVersion): CVRVersion {\n return v === null\n ? {stateVersion: majorVersionToString(0)}\n : {\n stateVersion: v.stateVersion,\n configVersion: (v.configVersion ?? 0) + 1,\n };\n}\n\nexport type NullableCVRVersion = CVRVersion | null;\n\nexport function cmpVersions(\n a: NullableCVRVersion,\n b: NullableCVRVersion,\n): number {\n return a === null && b === null\n ? 0\n : a === null\n ? -1\n : b === null\n ? 1\n : a.stateVersion < b.stateVersion\n ? -1\n : a.stateVersion > b.stateVersion\n ? 1\n : (a.configVersion ?? 0) - (b.configVersion ?? 0);\n}\n\nexport function maxVersion(a: CVRVersion, b?: CVRVersion): CVRVersion {\n return !b ? a : cmpVersions(b, a) > 0 ? b : a;\n}\n\nexport function versionToCookie(v: CVRVersion): string {\n return versionString(v);\n}\n\nexport function versionToNullableCookie(v: NullableCVRVersion): string | null {\n return v === null ? null : versionToCookie(v);\n}\n\nexport function cookieToVersion(cookie: string | null): NullableCVRVersion {\n if (cookie === null) {\n return null;\n }\n return versionFromString(cookie);\n}\n\n// Last Active tracking.\n\nexport const cvrIDSchema = v.object({id: v.string()});\nexport type CvrID = v.Infer<typeof cvrIDSchema>;\n\nconst cvrRecordSchema = v.object({\n /**\n * CVR records store the CVRVersion at which the record was last patched into\n * the CVR, which corresponds with a patch row that is cleaned up when the\n * record is changed (updated, deleted, and re-added in the case of rows).\n *\n * Tombstones are stored for row records but not for config records. This means\n * that \"orphaned\" delete patches for config records may exist, and therefore\n * scans of config patches must always run until the end of the list. On the\n * contrary, for row patches, the row record tombstones allow cleanup of delete\n * patches.\n */\n patchVersion: cvrVersionSchema,\n});\n\nexport const clientRecordSchema = v.object({\n /** The client ID, of which there can be multiple for a client group view. */\n id: v.string(),\n\n /** The client's desired query IDs. Patch information is stored in the QueryRecord. */\n desiredQueryIDs: v.array(v.string()),\n});\n\nexport type ClientRecord = v.Infer<typeof clientRecordSchema>;\n\nexport const baseQueryRecordSchema = v.object({\n /** The client-specified ID used to identify this query. Typically a hash. */\n id: v.string(),\n\n /**\n * The hash of the query after server-side transformations, which include:\n *\n * * Normalization (which may differ from what the client does)\n * * Query \"expansion\" to include primary keys and query-execution-related columns\n * * Authorization transforms\n *\n * Transformations depend on conditions that are independent of the db state version,\n * such as server-side logic and authorization policies. As such, the version of a CVR\n * version may need to be advanced independent of db state changes. This is done\n * via the `minorVersion` counter of the CVRVersion object, which is used to account\n * for both changes to the query set and changes to query transformations (which are\n * effectively remove-old-query + add-new-query).\n *\n * Note that the transformed AST itself is **not** stored, as the result of the previous\n * transformation is not useful in and of itself. If the current transformation results in\n * a different hash than that of the transformation used for the last version of the CVR,\n * it is simply handled by invalidating the existing rows, re-executed the query with\n * the new transformation, and advancing the CVR's `minorVersion` and this query's\n * `transformationVersion`.\n *\n * Note that the transformationHash is only stored when the query has reached the \"gotten\"\n * state. If the query is in the \"desired\" but not yet \"gotten\" state, the field is absent.\n */\n transformationHash: v.string().optional(),\n\n /**\n * The CVR version corresponding to the `transformationHash`. This essentially tracks when\n * this version of the query was effectively added to the CVR (as opposed to the\n * `patchVersion`, which is simply when the client was notified that its query was added\n * to the gotten set). Catchup of clients from old CVR versions require executing all\n * queries with a newer `transformationVersion`.\n */\n transformationVersion: cvrVersionSchema.optional(),\n\n /**\n * Hex-encoded XOR signature over `h64(JSON.stringify([schema, table, rowKey]))`\n * of every row currently attached to this query. Maintained incrementally by\n * `PipelineDriver` as ADDs / REMOVEs are yielded from the query's pipeline\n * (EDITs no-op), and persisted via `CVRQueryDrivenUpdater.flush` by a\n * signature-provider callback.\n *\n * Used to detect drift on re-hydration of queries containing the `Cap` operator,\n * which intentionally does not impose ordering and thus may pick a different N-row\n * subset on re-execution. Comparing the pre-hydration signature with the post-\n * hydration signature lets us force a `configVersion` bump so the standard CVR-diff\n * machinery emits the reconciling poke. Absent or `'0'` means the signature is\n * empty (no rows currently attached).\n */\n rowSetSignature: v.string().optional(),\n});\n\n/**\n * Internal queries track rows in the database for internal use, such as the\n * `lastMutationID`s in the `zero.clients` table. They participate in the standard\n * invalidation / update logic for row contents, but not in the desired/got or\n * size-based quota logic for client-requested queries.\n */\nexport const internalQueryRecordSchema = baseQueryRecordSchema.extend({\n type: v.literal('internal'),\n ast: astSchema,\n});\n\nexport type InternalQueryRecord = v.Infer<typeof internalQueryRecordSchema>;\n\nconst clientStateSchema = v.object({\n /**\n * The time at which the query was last inactivated. If this undefined or\n * missing then the query is active.\n *\n * Desired queries are always active and have an undefined inactivatedAt.\n */\n inactivatedAt: ttlClockSchema.optional(),\n\n /**\n * TTL, time to live in milliseconds. If the query is not updated within this\n * time. The time to live is the time after it has become inactive. Negative\n * values are treated as `'forever'`.\n *\n * We do clamp this to a maximum of 10 minutes, so that queries do not\n * live for a very long time in the CVR.\n */\n ttl: v.number(),\n\n /**\n * The version at which the client state changed (i.e. individual `patchVersion`s).\n */\n version: cvrVersionSchema,\n});\n\nconst externalQueryRecordSchema = baseQueryRecordSchema.extend({\n /**\n * The client state for this query, which includes the inactivatedAt, ttl and\n * version. The client state is stored in a record with the client ID as the\n * key.\n */\n clientState: v.record(clientStateSchema),\n\n // For queries, the `patchVersion` indicates when query was added to the got set,\n // and is absent if not yet gotten.\n patchVersion: cvrVersionSchema.optional(),\n});\n\nexport const clientQueryRecordSchema = externalQueryRecordSchema.extend({\n type: v.literal('client'),\n\n /** The original AST as supplied by the client. */\n ast: astSchema,\n});\n\nexport type ClientQueryRecord = v.Infer<typeof clientQueryRecordSchema>;\n\nexport const customQueryRecordSchema = externalQueryRecordSchema.extend({\n type: v.literal('custom'),\n name: v.string(),\n args: v.readonly(v.array(jsonSchema)),\n});\n\nexport type CustomQueryRecord = v.Infer<typeof customQueryRecordSchema>;\n\nexport const queryRecordSchema = v.union(\n clientQueryRecordSchema,\n customQueryRecordSchema,\n internalQueryRecordSchema,\n);\n\nexport type QueryRecord = v.Infer<typeof queryRecordSchema>;\n\nexport const rowIDSchema = v.object({\n schema: v.string(),\n table: v.string(),\n rowKey: v.record(jsonValueSchema),\n});\n\nexport type RowID = v.Infer<typeof rowIDSchema>;\n\nexport const rowRecordSchema = cvrRecordSchema.extend({\n id: rowIDSchema,\n rowVersion: v.string(), // '_0_version' of the row\n // query hashes => refCount, or `null` for a row that was removed from the\n // view (i.e. tombstone).\n refCounts: v.record(v.number()).nullable(),\n});\n\nexport type RowRecord = v.Infer<typeof rowRecordSchema>;\n\nexport const patchSchema = v.object({\n type: v.literalUnion('row', 'query'),\n op: v.literalUnion('put', 'del'),\n});\n\nexport const putRowPatchSchema = patchSchema.extend({\n type: v.literal('row'),\n op: v.literal('put'),\n id: rowIDSchema,\n rowVersion: v.string(), // '_0_version' of the row\n});\n\nexport type PutRowPatch = v.Infer<typeof putRowPatchSchema>;\n\nexport const delRowPatchSchema = patchSchema.extend({\n type: v.literal('row'),\n op: v.literal('del'),\n id: rowIDSchema,\n});\n\nexport type DelRowPatch = v.Infer<typeof delRowPatchSchema>;\n\nexport const rowPatchSchema = v.union(putRowPatchSchema, delRowPatchSchema);\n\nexport type RowPatch = v.Infer<typeof rowPatchSchema>;\n\nexport const queryPatchSchema = patchSchema.extend({\n type: v.literal('query'),\n id: v.string(),\n clientID: v.string().optional(), // defined for \"desired\", undefined for \"got\"\n});\n\nexport type QueryPatch = v.Infer<typeof queryPatchSchema>;\n\nexport type PutQueryPatch = QueryPatch & {op: 'put'};\nexport type DelQueryPatch = QueryPatch & {op: 'del'};\n\nexport const metadataPatchSchema = queryPatchSchema;\n\nexport type MetadataPatch = v.Infer<typeof metadataPatchSchema>;\n\nexport function versionString(v: CVRVersion) {\n // The separator (e.g. \":\") needs to be lexicographically greater than the\n // storage key path separator (e.g. \"/\") so that \"01/row-hash\" is less than \"01:01/row-hash\".\n // In particular, the traditional separator for major.minor versions (\".\") does not\n // satisfy this quality.\n return v.configVersion\n ? `${v.stateVersion}:${versionToLexi(v.configVersion)}`\n : v.stateVersion;\n}\n\nexport function versionFromString(str: string): CVRVersion {\n const parts = str.split(':');\n const stateVersion = parts[0];\n switch (parts.length) {\n case 1: {\n stateVersionFromString(stateVersion); // Purely for validation.\n return {stateVersion};\n }\n case 2: {\n const configVersion = versionFromLexi(parts[1]);\n if (configVersion > BigInt(Number.MAX_SAFE_INTEGER)) {\n throw new Error(`minorVersion ${parts[1]} exceeds max safe integer`);\n }\n return {stateVersion, configVersion: Number(configVersion)};\n }\n default:\n throw new TypeError(`Invalid version string ${str}`);\n }\n}\n\nexport function queryRecordToQueryRow(\n clientGroupID: string,\n query: QueryRecord,\n): QueriesRow {\n switch (query.type) {\n case 'internal':\n return {\n clientGroupID,\n queryHash: query.id,\n clientAST: query.ast,\n queryName: null,\n queryArgs: null,\n patchVersion: null,\n transformationHash: query.transformationHash ?? null,\n transformationVersion: maybeVersionString(query.transformationVersion),\n internal: true,\n deleted: false, // put vs del \"got\" query\n rowSetSignature: query.rowSetSignature ?? null,\n };\n case 'client':\n return {\n clientGroupID,\n queryHash: query.id,\n clientAST: query.ast,\n queryName: null,\n queryArgs: null,\n patchVersion: maybeVersionString(query.patchVersion),\n transformationHash: query.transformationHash ?? null,\n transformationVersion: maybeVersionString(query.transformationVersion),\n internal: null,\n deleted: false, // put vs del \"got\" query\n rowSetSignature: query.rowSetSignature ?? null,\n };\n case 'custom':\n return {\n clientGroupID,\n queryHash: query.id,\n clientAST: null,\n queryName: query.name,\n queryArgs: query.args,\n patchVersion: maybeVersionString(query.patchVersion),\n transformationHash: query.transformationHash ?? null,\n transformationVersion: maybeVersionString(query.transformationVersion),\n internal: null,\n deleted: false, // put vs del \"got\" query\n rowSetSignature: query.rowSetSignature ?? null,\n };\n }\n}\n\nexport const maybeVersionString = (v: CVRVersion | undefined) =>\n v ? versionString(v) : null;\n"],"mappings":";;;;;;;;AAYA,IAAa,mBAAmB,eAAE,OAAO;CAIvC,cAAc,eAAE,QAAQ;CAkBxB,eAAe,eAAE,QAAQ,CAAC,UAAU;CACrC,CAAC;AAIF,IAAa,oBAAgC,EAC3C,cAAc,qBAAqB,EAAE,EACtC;AAED,SAAgB,SAAS,GAAmC;AAC1D,QAAO,MAAM,OACT,EAAC,cAAc,qBAAqB,EAAE,EAAC,GACvC;EACE,cAAc,EAAE;EAChB,gBAAgB,EAAE,iBAAiB,KAAK;EACzC;;AAKP,SAAgB,YACd,GACA,GACQ;AACR,QAAO,MAAM,QAAQ,MAAM,OACvB,IACA,MAAM,OACJ,KACA,MAAM,OACJ,IACA,EAAE,eAAe,EAAE,eACjB,KACA,EAAE,eAAe,EAAE,eACjB,KACC,EAAE,iBAAiB,MAAM,EAAE,iBAAiB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BAAiB,CACjD,OAAM,IAAI,MAAM,gBAAgB,MAAM,GAAG,2BAA2B;AAEtE,UAAO;IAAC;IAAc,eAAe,OAAO,cAAc;IAAC;;EAE7D,QACE,OAAM,IAAI,UAAU,0BAA0B,MAAM;;;AAI1D,SAAgB,sBACd,eACA,OACY;AACZ,SAAQ,MAAM,MAAd;EACE,KAAK,WACH,QAAO;GACL;GACA,WAAW,MAAM;GACjB,WAAW,MAAM;GACjB,WAAW;GACX,WAAW;GACX,cAAc;GACd,oBAAoB,MAAM,sBAAsB;GAChD,uBAAuB,mBAAmB,MAAM,sBAAsB;GACtE,UAAU;GACV,SAAS;GACT,iBAAiB,MAAM,mBAAmB;GAC3C;EACH,KAAK,SACH,QAAO;GACL;GACA,WAAW,MAAM;GACjB,WAAW,MAAM;GACjB,WAAW;GACX,WAAW;GACX,cAAc,mBAAmB,MAAM,aAAa;GACpD,oBAAoB,MAAM,sBAAsB;GAChD,uBAAuB,mBAAmB,MAAM,sBAAsB;GACtE,UAAU;GACV,SAAS;GACT,iBAAiB,MAAM,mBAAmB;GAC3C;EACH,KAAK,SACH,QAAO;GACL;GACA,WAAW,MAAM;GACjB,WAAW;GACX,WAAW,MAAM;GACjB,WAAW,MAAM;GACjB,cAAc,mBAAmB,MAAM,aAAa;GACpD,oBAAoB,MAAM,sBAAsB;GAChD,uBAAuB,mBAAmB,MAAM,sBAAsB;GACtE,UAAU;GACV,SAAS;GACT,iBAAiB,MAAM,mBAAmB;GAC3C;;;AAIP,IAAa,sBAAsB,MACjC,IAAI,cAAc,EAAE,GAAG"}
@@ -1 +1 @@
1
- {"version":3,"file":"view-syncer.d.ts","sourceRoot":"","sources":["../../../../../../zero-cache/src/services/view-syncer/view-syncer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAcjD,OAAO,KAAK,EAAC,2BAA2B,EAAC,MAAM,yDAAyD,CAAC;AACzG,OAAO,KAAK,EAEV,qBAAqB,E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Y,IAAI,MAAM;CAKvB"}
@@ -8,7 +8,7 @@ import { stringify } from "../../../../shared/src/bigint-json.js";
8
8
  import { manualSpan, startAsyncSpan, startSpan } from "../../../../otel/src/span.js";
9
9
  import { ZERO_VERSION_COLUMN_NAME } from "../replicator/schema/constants.js";
10
10
  import { transformAndHashQuery } from "../../auth/read-authorizer.js";
11
- import { getOrCreateCounter, getOrCreateHistogram, getOrCreateUpDownCounter } from "../../observability/metrics.js";
11
+ import { getOrCreateCounter, getOrCreateLatencyHistogram, getOrCreateUpDownCounter } from "../../observability/metrics.js";
12
12
  import { rowIDString } from "../../types/row-key.js";
13
13
  import "../replicator/schema/replication-state.js";
14
14
  import { ResetPipelinesSignal } from "./snapshotter.js";
@@ -86,25 +86,13 @@ var ViewSyncerService = class {
86
86
  #queryReplacements = /* @__PURE__ */ new Map();
87
87
  #activeClients = getOrCreateUpDownCounter("sync", "active-clients", "Number of active sync clients");
88
88
  #hydrations = getOrCreateCounter("sync", "hydration", "Number of query hydrations");
89
- #hydrationTime = getOrCreateHistogram("sync", "hydration-time", {
90
- description: "Time to hydrate a query.",
91
- unit: "s"
92
- });
93
- #transactionAdvanceTime = getOrCreateHistogram("sync", "advance-time", {
94
- description: "Time to advance all queries for a given client group after applying a new transaction to the replica.",
95
- unit: "s"
96
- });
89
+ #hydrationTime = getOrCreateLatencyHistogram("sync", "hydration-time", "Time to hydrate a query.");
90
+ #transactionAdvanceTime = getOrCreateLatencyHistogram("sync", "advance-time", "Time to advance all queries for a given client group after applying a new transaction to the replica.");
97
91
  #queryTransformations = getOrCreateCounter("sync", "query.transformations", "Number of query transformations performed");
98
- #queryTransformationTime = getOrCreateHistogram("sync", "query.transformation-time", {
99
- description: "Time to transform custom queries via API server",
100
- unit: "s"
101
- });
92
+ #queryTransformationTime = getOrCreateLatencyHistogram("sync", "query.transformation-time", "Time to transform custom queries via API server.");
102
93
  #queryTransformationHashChanges = getOrCreateCounter("sync", "query.transformation-hash-changes", "Number of times query transformation hash changed");
103
94
  #queryTransformationNoOps = getOrCreateCounter("sync", "query.transformation-no-ops", "Number of times query transformation resulted in no-op (hash unchanged)");
104
- #lockWaitTime = getOrCreateHistogram("sync", "lock-wait-time", {
105
- description: "Time spent waiting to acquire the ViewSyncer lock.",
106
- unit: "s"
107
- });
95
+ #lockWaitTime = getOrCreateLatencyHistogram("sync", "lock-wait-time", "Time spent waiting to acquire the ViewSyncer lock.");
108
96
  #pipelineResets = getOrCreateCounter("sync", "pipeline-resets", "Number of pipeline resets");
109
97
  #inspectorDelegate;
110
98
  #config;
@@ -132,7 +120,7 @@ var ViewSyncerService = class {
132
120
  this.#lc.debug?.("about to acquire lock for cvr ", rid);
133
121
  const lockWaitStart = performance.now();
134
122
  return this.#lock.withLock(async () => {
135
- this.#lockWaitTime.record((performance.now() - lockWaitStart) / 1e3);
123
+ this.#lockWaitTime.recordMs(performance.now() - lockWaitStart);
136
124
  this.#lc.debug?.("acquired lock in #runInLockWithCVR ", rid);
137
125
  const lc = this.#lc.withContext("lock", rid);
138
126
  if (!this.#stateChanges.active) {
@@ -625,7 +613,7 @@ var ViewSyncerService = class {
625
613
  });
626
614
  const elapsed = timer.totalElapsed();
627
615
  this.#hydrations.add(1);
628
- this.#hydrationTime.record(elapsed / 1e3);
616
+ this.#hydrationTime.recordMs(elapsed);
629
617
  this.#addQueryMaterializationServerMetric(transformationHash, elapsed);
630
618
  lc.debug?.(`hydrated ${count} rows for ${queryID} (${elapsed} ms)`);
631
619
  }
@@ -727,8 +715,8 @@ var ViewSyncerService = class {
727
715
  this.#queryTransformations.add(1, { result: "error" });
728
716
  throw e;
729
717
  } finally {
730
- const transformDuration = (performance.now() - transformStart) / 1e3;
731
- this.#queryTransformationTime.record(transformDuration);
718
+ const transformDuration = performance.now() - transformStart;
719
+ this.#queryTransformationTime.recordMs(transformDuration);
732
720
  }
733
721
  const successfullyTransformedCustomQueries = /* @__PURE__ */ new Map();
734
722
  erroredQueryIDs = this.#processTransformedCustomQueries(lc, transformedCustomQueries.result, (q) => {
@@ -756,10 +744,11 @@ var ViewSyncerService = class {
756
744
  }
757
745
  }
758
746
  const removeQueriesQueryIds = new Set([...Object.values(cvr.queries).filter((q) => expired(ttlClock, q)).map((q) => q.id), ...erroredQueryIDs || []]);
759
- const addQueries = transformedQueries.map(({ id, transformed }) => ({
747
+ const addQueries = transformedQueries.map(({ id, origQuery, transformed }) => ({
760
748
  id,
761
749
  ast: transformed.transformedAst,
762
- transformationHash: transformed.transformationHash
750
+ transformationHash: transformed.transformationHash,
751
+ name: origQuery.type === "custom" ? origQuery.name : void 0
763
752
  })).filter((q) => !removeQueriesQueryIds.has(q.id) && this.#pipelines.queries().get(q.id)?.transformationHash !== q.transformationHash);
764
753
  lc.info?.(`syncQueryPipelineSet: ${cvrQueryEntires.length} CVR queries, ${customQueriesToTransform.length} custom re-transformed, ${erroredQueryIDs?.length ?? 0} errored, ${removeQueriesQueryIds.size} to remove, ${addQueries.length} to add`);
765
754
  for (const q of addQueries) {
@@ -805,7 +794,7 @@ var ViewSyncerService = class {
805
794
  const stateVersion = this.#pipelines.currentVersion();
806
795
  lc = lc.withContext("stateVersion", stateVersion);
807
796
  lc.info?.(`hydrating ${addQueries.length} queries`);
808
- const updater = new CVRQueryDrivenUpdater(this.#cvrStore, cvr, stateVersion, this.#pipelines.replicaVersion);
797
+ const updater = new CVRQueryDrivenUpdater(this.#cvrStore, cvr, stateVersion, this.#pipelines.replicaVersion, (queryID) => this.#pipelines.rowSetSignature(queryID));
809
798
  const { newVersion, queryPatches } = updater.trackQueries(lc, addQueries, removeQueries);
810
799
  const pokers = startPoke(this.#getClients(), newVersion);
811
800
  for (const patch of queryPatches) await pokers.addPatch(patch);
@@ -832,11 +821,12 @@ var ViewSyncerService = class {
832
821
  if (elapsed > slowHydrateThreshold) lc.warn?.("Slow query materialization", elapsed, q.ast);
833
822
  manualSpan(tracer, "vs.addAndConsumeQuery", elapsed, {
834
823
  hash: q.id,
835
- transformationHash: q.transformationHash
824
+ transformationHash: q.transformationHash,
825
+ ...q.name !== void 0 && { name: q.name }
836
826
  });
837
827
  }
838
828
  hydrations.add(1);
839
- hydrationTime.record(totalProcessTime / 1e3);
829
+ hydrationTime.recordMs(totalProcessTime);
840
830
  }
841
831
  await this.#processChanges(lc, timer, generateRowChanges(this.#slowHydrateThreshold), updater, pokers);
842
832
  await startAsyncSpan(tracer, "vs.#syncQueryPipelineSet.deleteUnreferencedRows", async () => {
@@ -991,7 +981,7 @@ var ViewSyncerService = class {
991
981
  const timer = new TimeSliceTimer(lc);
992
982
  const { version, numChanges, changes } = this.#pipelines.advance(timer);
993
983
  lc = lc.withContext("newVersion", version);
994
- const updater = new CVRQueryDrivenUpdater(this.#cvrStore, cvr, version, this.#pipelines.replicaVersion);
984
+ const updater = new CVRQueryDrivenUpdater(this.#cvrStore, cvr, version, this.#pipelines.replicaVersion, (queryID) => this.#pipelines.rowSetSignature(queryID));
995
985
  const pokers = startPoke(this.#getClients(cvr.version), updater.updatedVersion());
996
986
  lc.debug?.(`applying ${numChanges} to advance to ${version}`);
997
987
  try {
@@ -1009,7 +999,7 @@ var ViewSyncerService = class {
1009
999
  const wallTime = performance.now() - start;
1010
1000
  const totalProcessTime = timer.totalElapsed();
1011
1001
  lc.info?.(`finished processing advancement of ${numChanges} changes ((process: ${totalProcessTime} ms, wall: ${wallTime} ms))`);
1012
- this.#transactionAdvanceTime.record(totalProcessTime / 1e3);
1002
+ this.#transactionAdvanceTime.recordMs(totalProcessTime);
1013
1003
  return "success";
1014
1004
  });
1015
1005
  }