@powersync/service-sync-rules 0.0.0-dev-20260803144812 → 0.0.0-dev-20260929095716

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 (166) hide show
  1. package/README.md +49 -14
  2. package/dist/BucketSource.d.ts +2 -2
  3. package/dist/ConnectionConfig.d.ts +39 -0
  4. package/dist/ConnectionConfig.js +97 -0
  5. package/dist/ConnectionConfig.js.map +1 -0
  6. package/dist/HydratedSyncConfig.d.ts +11 -2
  7. package/dist/HydratedSyncConfig.js +18 -4
  8. package/dist/HydratedSyncConfig.js.map +1 -1
  9. package/dist/HydrationState.d.ts +2 -0
  10. package/dist/HydrationState.js.map +1 -1
  11. package/dist/SqlSyncRules.d.ts +15 -0
  12. package/dist/SqlSyncRules.js +3 -1
  13. package/dist/SqlSyncRules.js.map +1 -1
  14. package/dist/StorageVersion.js +2 -1
  15. package/dist/StorageVersion.js.map +1 -1
  16. package/dist/SyncConfig.d.ts +11 -3
  17. package/dist/SyncConfig.js +16 -11
  18. package/dist/SyncConfig.js.map +1 -1
  19. package/dist/SyncConfigParserHooks.d.ts +103 -0
  20. package/dist/SyncConfigParserHooks.js +11 -0
  21. package/dist/SyncConfigParserHooks.js.map +1 -0
  22. package/dist/compatibility.d.ts +2 -1
  23. package/dist/compatibility.js +4 -2
  24. package/dist/compatibility.js.map +1 -1
  25. package/dist/compiler/bucket_resolver.d.ts +1 -0
  26. package/dist/compiler/bucket_resolver.js +22 -12
  27. package/dist/compiler/bucket_resolver.js.map +1 -1
  28. package/dist/compiler/compatibility.d.ts +38 -9
  29. package/dist/compiler/compatibility.js +81 -11
  30. package/dist/compiler/compatibility.js.map +1 -1
  31. package/dist/compiler/compiler.d.ts +84 -16
  32. package/dist/compiler/compiler.js +112 -16
  33. package/dist/compiler/compiler.js.map +1 -1
  34. package/dist/compiler/equality.d.ts +2 -2
  35. package/dist/compiler/equality.js +2 -2
  36. package/dist/compiler/expression.d.ts +20 -18
  37. package/dist/compiler/expression.js +23 -14
  38. package/dist/compiler/expression.js.map +1 -1
  39. package/dist/compiler/filter.d.ts +4 -4
  40. package/dist/compiler/filter.js +5 -4
  41. package/dist/compiler/filter.js.map +1 -1
  42. package/dist/compiler/ir_to_sync_plan.d.ts +4 -2
  43. package/dist/compiler/ir_to_sync_plan.js +40 -36
  44. package/dist/compiler/ir_to_sync_plan.js.map +1 -1
  45. package/dist/compiler/parser.d.ts +1 -1
  46. package/dist/compiler/parser.js +2 -2
  47. package/dist/compiler/querier_graph.js +43 -24
  48. package/dist/compiler/querier_graph.js.map +1 -1
  49. package/dist/compiler/rows.d.ts +23 -29
  50. package/dist/compiler/rows.js +83 -59
  51. package/dist/compiler/rows.js.map +1 -1
  52. package/dist/compiler/sqlite.js +1 -2
  53. package/dist/compiler/sqlite.js.map +1 -1
  54. package/dist/compiler/table.d.ts +5 -4
  55. package/dist/compiler/table.js +6 -7
  56. package/dist/compiler/table.js.map +1 -1
  57. package/dist/events/CompiledEventSourceQuery.d.ts +51 -0
  58. package/dist/events/CompiledEventSourceQuery.js +119 -0
  59. package/dist/events/CompiledEventSourceQuery.js.map +1 -0
  60. package/dist/events/EventDescriptor.d.ts +26 -0
  61. package/dist/events/EventDescriptor.js +2 -0
  62. package/dist/events/EventDescriptor.js.map +1 -0
  63. package/dist/from_yaml.d.ts +14 -1
  64. package/dist/from_yaml.js +101 -39
  65. package/dist/from_yaml.js.map +1 -1
  66. package/dist/index.d.ts +5 -2
  67. package/dist/index.js +5 -2
  68. package/dist/index.js.map +1 -1
  69. package/dist/json.d.ts +7 -0
  70. package/dist/json.js +2 -0
  71. package/dist/json.js.map +1 -0
  72. package/dist/json_schema.d.ts +11 -0
  73. package/dist/json_schema.js +27 -4
  74. package/dist/json_schema.js.map +1 -1
  75. package/dist/legacy/BaseSqlDataQuery.d.ts +12 -0
  76. package/dist/legacy/BaseSqlDataQuery.js +3 -0
  77. package/dist/legacy/BaseSqlDataQuery.js.map +1 -1
  78. package/dist/legacy/SqlBucketDescriptor.d.ts +9 -0
  79. package/dist/legacy/SqlBucketDescriptor.js +6 -0
  80. package/dist/legacy/SqlBucketDescriptor.js.map +1 -1
  81. package/dist/legacy/SqlDataQuery.d.ts +6 -0
  82. package/dist/legacy/SqlDataQuery.js +3 -0
  83. package/dist/legacy/SqlDataQuery.js.map +1 -1
  84. package/dist/legacy/SqlParameterQuery.d.ts +4 -0
  85. package/dist/legacy/SqlParameterQuery.js +1 -0
  86. package/dist/legacy/SqlParameterQuery.js.map +1 -1
  87. package/dist/legacy/StaticSqlParameterQuery.d.ts +4 -0
  88. package/dist/legacy/StaticSqlParameterQuery.js +1 -0
  89. package/dist/legacy/StaticSqlParameterQuery.js.map +1 -1
  90. package/dist/legacy/TableQuerySchema.d.ts +1 -0
  91. package/dist/legacy/TableQuerySchema.js +1 -0
  92. package/dist/legacy/TableQuerySchema.js.map +1 -1
  93. package/dist/legacy/TableValuedFunctionSqlParameterQuery.d.ts +4 -0
  94. package/dist/legacy/TableValuedFunctionSqlParameterQuery.js +1 -0
  95. package/dist/legacy/TableValuedFunctionSqlParameterQuery.js.map +1 -1
  96. package/dist/legacy/sql_filters.d.ts +13 -0
  97. package/dist/legacy/sql_filters.js +10 -0
  98. package/dist/legacy/sql_filters.js.map +1 -1
  99. package/dist/legacy/sql_support.d.ts +33 -0
  100. package/dist/legacy/sql_support.js +33 -0
  101. package/dist/legacy/sql_support.js.map +1 -1
  102. package/dist/legacy/streams/filter.d.ts +22 -0
  103. package/dist/legacy/streams/filter.js +19 -0
  104. package/dist/legacy/streams/filter.js.map +1 -1
  105. package/dist/legacy/streams/from_sql.d.ts +3 -0
  106. package/dist/legacy/streams/from_sql.js +4 -1
  107. package/dist/legacy/streams/from_sql.js.map +1 -1
  108. package/dist/legacy/streams/functions.d.ts +3 -0
  109. package/dist/legacy/streams/functions.js +3 -0
  110. package/dist/legacy/streams/functions.js.map +1 -1
  111. package/dist/legacy/streams/parameter.d.ts +10 -0
  112. package/dist/legacy/streams/stream.d.ts +7 -1
  113. package/dist/legacy/streams/stream.js +7 -1
  114. package/dist/legacy/streams/stream.js.map +1 -1
  115. package/dist/legacy/streams/variant.d.ts +6 -0
  116. package/dist/legacy/streams/variant.js +1 -0
  117. package/dist/legacy/streams/variant.js.map +1 -1
  118. package/dist/legacy/validators.d.ts +1 -0
  119. package/dist/legacy/validators.js +1 -0
  120. package/dist/legacy/validators.js.map +1 -1
  121. package/dist/schema-generators/RustSchemaGenerator.d.ts +22 -0
  122. package/dist/schema-generators/RustSchemaGenerator.js +120 -0
  123. package/dist/schema-generators/RustSchemaGenerator.js.map +1 -0
  124. package/dist/schema-generators/generators.d.ts +2 -0
  125. package/dist/schema-generators/generators.js +2 -0
  126. package/dist/schema-generators/generators.js.map +1 -1
  127. package/dist/schema-generators/schema-generators.d.ts +1 -0
  128. package/dist/schema-generators/schema-generators.js +1 -0
  129. package/dist/schema-generators/schema-generators.js.map +1 -1
  130. package/dist/sql_functions.d.ts +1 -1
  131. package/dist/sync_plan/evaluator/bucket_data_source.js +11 -53
  132. package/dist/sync_plan/evaluator/bucket_data_source.js.map +1 -1
  133. package/dist/sync_plan/evaluator/bucket_source.js +1 -1
  134. package/dist/sync_plan/evaluator/index.d.ts +2 -7
  135. package/dist/sync_plan/evaluator/index.js +7 -7
  136. package/dist/sync_plan/evaluator/index.js.map +1 -1
  137. package/dist/sync_plan/evaluator/parameter_evaluator.d.ts +1 -1
  138. package/dist/sync_plan/evaluator/parameter_evaluator.js +12 -8
  139. package/dist/sync_plan/evaluator/parameter_evaluator.js.map +1 -1
  140. package/dist/sync_plan/evaluator/row_projection.d.ts +22 -0
  141. package/dist/sync_plan/evaluator/row_projection.js +71 -0
  142. package/dist/sync_plan/evaluator/row_projection.js.map +1 -0
  143. package/dist/sync_plan/plan.d.ts +43 -6
  144. package/dist/sync_plan/plan_equality_serialized.d.ts +12 -2
  145. package/dist/sync_plan/plan_equality_serialized.js +56 -0
  146. package/dist/sync_plan/plan_equality_serialized.js.map +1 -1
  147. package/dist/sync_plan/schema_inference.d.ts +1 -1
  148. package/dist/sync_plan/schema_inference.js +1 -1
  149. package/dist/sync_plan/serialize.d.ts +52 -5
  150. package/dist/sync_plan/serialize.js +125 -20
  151. package/dist/sync_plan/serialize.js.map +1 -1
  152. package/dist/utils.d.ts +1 -0
  153. package/dist/utils.js +43 -12
  154. package/dist/utils.js.map +1 -1
  155. package/dist/yaml_source_locations.d.ts +14 -0
  156. package/dist/yaml_source_locations.js +117 -0
  157. package/dist/yaml_source_locations.js.map +1 -0
  158. package/dist/yaml_validation.js.map +1 -1
  159. package/package.json +2 -1
  160. package/schema/sync_rules.json +49 -3
  161. package/dist/events/SqlEventDescriptor.d.ts +0 -20
  162. package/dist/events/SqlEventDescriptor.js +0 -51
  163. package/dist/events/SqlEventDescriptor.js.map +0 -1
  164. package/dist/events/SqlEventSourceQuery.d.ts +0 -20
  165. package/dist/events/SqlEventSourceQuery.js +0 -125
  166. package/dist/events/SqlEventSourceQuery.js.map +0 -1
@@ -0,0 +1,103 @@
1
+ import type { JsonObject } from './json.js';
2
+ import type { SyncConfig } from './SyncConfig.js';
3
+ import type { TablePattern } from './TablePattern.js';
4
+ /**
5
+ * A decoded config path, for example `['config', 'connections', 'default', 'tables', 'orders', 'filter']`.
6
+ */
7
+ export type SyncConfigSourcePath = readonly (string | number)[];
8
+ export type SyncConfigSourceLocationTarget = 'key' | 'value';
9
+ /**
10
+ * Offsets into the authored config, compatible with locations returned by service diagnostics.
11
+ */
12
+ export interface SyncConfigSourceSpan {
13
+ start_offset: number;
14
+ end_offset: number;
15
+ }
16
+ /**
17
+ * A parser warning or failure, optionally pointing to the relevant config key or value.
18
+ */
19
+ export interface SyncConfigDiagnostic {
20
+ level: 'warning' | 'fatal';
21
+ message: string;
22
+ location?: SyncConfigSourceSpan;
23
+ }
24
+ export interface SyncConfigSourceLocationResolver {
25
+ /**
26
+ * Resolve a field to its source span, falling back to its nearest existing ancestor.
27
+ */
28
+ getLocation(path: SyncConfigSourcePath, target?: SyncConfigSourceLocationTarget): SyncConfigSourceSpan | undefined;
29
+ }
30
+ /**
31
+ * Context for parsing input sync config.
32
+ */
33
+ export interface SyncConfigParserContext {
34
+ readonly defaultSchema: string;
35
+ /**
36
+ * Candidate being assembled. With throwOnError: false, a partial config may be returned with fatal diagnostics.
37
+ * Store options on the appropriate config fields.
38
+ */
39
+ parsedConfig: SyncConfig;
40
+ /**
41
+ * Sources selected by SQL. Additional parsers may inspect these, but cannot add replication sources.
42
+ */
43
+ sourceTables: readonly TablePattern[];
44
+ /**
45
+ * Utility helpers for determining source locations.
46
+ */
47
+ sourceLocations: SyncConfigSourceLocationResolver;
48
+ /**
49
+ * Report a diagnostic found while parsing.
50
+ */
51
+ reportDiagnostic(diagnostic: SyncConfigDiagnostic): void;
52
+ }
53
+ /**
54
+ * Context for validating persisted sync config.
55
+ */
56
+ export interface PersistedSyncConfigParserContext {
57
+ /**
58
+ * Default schema used to resolve unqualified table names during validation.
59
+ * Some callers supply a placeholder; do not persist names qualified using this value.
60
+ */
61
+ readonly defaultSchema: string;
62
+ /**
63
+ * Report a warning or fatal error found while validating the persisted config.
64
+ * Include a config source location when available. Fatal errors prevent the config from loading.
65
+ */
66
+ reportDiagnostic(diagnostic: SyncConfigDiagnostic): void;
67
+ }
68
+ /**
69
+ * Additional deterministic parsing/validation, registered per service rather than globally or by connection type.
70
+ * A hook identifies its own fields and leaves unrelated input alone. Source I/O belongs in source validation.
71
+ */
72
+ export interface AdditionalSyncConfigParser {
73
+ /**
74
+ * A unique ID for the parser. Persisted sync configs store these IDs to validate
75
+ * if modules which created the persisted config are present.
76
+ */
77
+ readonly id: string;
78
+ /**
79
+ * Mutates an isolated schema before parsing.
80
+ */
81
+ extendJsonSchema?(options: {
82
+ schema: JsonObject;
83
+ }): void;
84
+ /**
85
+ * `config` is decoded sync config. Everything else needed to parse it is supplied through `context`.
86
+ * Parse module-owned input into context.parsedConfig, including connectionConfig entries for this module.
87
+ * Core does not copy connection options from the input or normalize the parser's output here.
88
+ * For a PrecompiledSyncConfig, add this parser's ID to parsedConfig.plan.moduleData with a null value
89
+ * when the config requires this module. The plan's keys determine which parsers must be present on reload.
90
+ */
91
+ parse(options: {
92
+ config: unknown;
93
+ context: SyncConfigParserContext;
94
+ }): void;
95
+ /**
96
+ * Validate saved config fields without reparsing their original config or requiring config source locations.
97
+ */
98
+ validatePersisted?(options: {
99
+ config: SyncConfig;
100
+ context: PersistedSyncConfigParserContext;
101
+ }): void;
102
+ }
103
+ export declare function validateAdditionalSyncConfigParsers(parsers: readonly AdditionalSyncConfigParser[]): void;
@@ -0,0 +1,11 @@
1
+ export function validateAdditionalSyncConfigParsers(parsers) {
2
+ const ids = new Set();
3
+ for (const parser of parsers) {
4
+ if (!parser.id)
5
+ throw new Error('A sync config parser id must not be empty.');
6
+ if (ids.has(parser.id))
7
+ throw new Error(`A sync config parser is already registered with id '${parser.id}'.`);
8
+ ids.add(parser.id);
9
+ }
10
+ }
11
+ //# sourceMappingURL=SyncConfigParserHooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SyncConfigParserHooks.js","sourceRoot":"","sources":["../src/SyncConfigParserHooks.ts"],"names":[],"mappings":"AAyGA,MAAM,UAAU,mCAAmC,CAAC,OAA8C;IAChG,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,IAAI,CAAC,MAAM,CAAC,EAAE;YAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;QAC9E,IAAI,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,uDAAuD,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC;QAC9G,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
@@ -17,7 +17,7 @@ export declare class TimeValuePrecision {
17
17
  * A historical issue of the PowerSync service that can only be changed in a backwards-incompatible manner.
18
18
  *
19
19
  * To avoid breaking existing users, fixes to those quirks are opt-in: Users either have to use `fixed_quirks` list when
20
- * defining sync rules or use a new feature such as sync streams where these issues are fixed by default.
20
+ * defining legacy Sync Rules or use a new feature such as Sync Streams where these issues are fixed by default.
21
21
  */
22
22
  export declare class CompatibilityOption {
23
23
  readonly name: string;
@@ -29,6 +29,7 @@ export declare class CompatibilityOption {
29
29
  static fixedJsonExtract: CompatibilityOption;
30
30
  static customTypes: CompatibilityOption;
31
31
  static sqliteExpressionEngine: CompatibilityOption;
32
+ static fixedBooleanInJson: CompatibilityOption;
32
33
  static byName: Record<string, CompatibilityOption>;
33
34
  }
34
35
  export interface CompatibilityContextOptions {
@@ -26,7 +26,7 @@ export class TimeValuePrecision {
26
26
  * A historical issue of the PowerSync service that can only be changed in a backwards-incompatible manner.
27
27
  *
28
28
  * To avoid breaking existing users, fixes to those quirks are opt-in: Users either have to use `fixed_quirks` list when
29
- * defining sync rules or use a new feature such as sync streams where these issues are fixed by default.
29
+ * defining legacy Sync Rules or use a new feature such as Sync Streams where these issues are fixed by default.
30
30
  */
31
31
  export class CompatibilityOption {
32
32
  name;
@@ -42,12 +42,14 @@ export class CompatibilityOption {
42
42
  static fixedJsonExtract = new CompatibilityOption('fixed_json_extract', "Old versions of the sync service used to treat `->> 'foo.bar'` as a two-element JSON path. With this compatibility option enabled, it follows modern SQLite and treats it as a single key. The `$.` prefix would be required to split on `.`.", CompatibilityEdition.SYNC_STREAMS);
43
43
  static customTypes = new CompatibilityOption('custom_postgres_types', 'Map custom Postgres types into appropriate structures instead of syncing the raw string.', CompatibilityEdition.SYNC_STREAMS);
44
44
  static sqliteExpressionEngine = new CompatibilityOption('unstable_sqlite_expression_engine', 'Experimental option to evaluate functions and operators in Sync Streams with SQLite instead of a JavaScript implementation.', null);
45
+ static fixedBooleanInJson = new CompatibilityOption('fixed_booleans_in_json', 'Consistently sync boolean values of a JSON object or array in source data as booleans (instead of integers 0/1).', null);
45
46
  static byName = Object.freeze({
46
47
  timestamps_iso8601: this.timestampsIso8601,
47
48
  versioned_bucket_ids: this.versionedBucketIds,
48
49
  fixed_json_extract: this.fixedJsonExtract,
49
50
  custom_postgres_types: this.customTypes,
50
- unstable_sqlite_expression_engine: this.sqliteExpressionEngine
51
+ unstable_sqlite_expression_engine: this.sqliteExpressionEngine,
52
+ fixed_booleans_in_json: this.fixedBooleanInJson
51
53
  });
52
54
  }
53
55
  export class CompatibilityContext {
@@ -1 +1 @@
1
- {"version":3,"file":"compatibility.js","sourceRoot":"","sources":["../src/compatibility.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC9B,mEAAU,CAAA;IACV,+EAAgB,CAAA;IAChB,uFAAoB,CAAA;AACtB,CAAC,EAJW,oBAAoB,KAApB,oBAAoB,QAI/B;AAED,MAAM,OAAO,kBAAkB;IAElB;IACA;IAFX,YACW,IAAY,EACZ,eAAuB;QADvB,SAAI,GAAJ,IAAI,CAAQ;QACZ,oBAAe,GAAf,eAAe,CAAQ;IAC/B,CAAC;IAEJ,MAAM,CAAC,OAAO,GAAG,IAAI,kBAAkB,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;IACtD,MAAM,CAAC,YAAY,GAAG,IAAI,kBAAkB,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC;IAChE,MAAM,CAAC,YAAY,GAAG,IAAI,kBAAkB,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC;IAChE,MAAM,CAAC,WAAW,GAAG,IAAI,kBAAkB,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC;IAE9D,MAAM,CAAC,MAAM,GAAuC,MAAM,CAAC,MAAM,CAAC;QAChE,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,YAAY,EAAE,IAAI,CAAC,YAAY;QAC/B,WAAW,EAAE,IAAI,CAAC,WA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mB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACvD,IAAI,WAAW,EAAE,CAAC;gBAChB,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;YACtC,CAAC;QACH,CAAC;QAED,IAAI,qBAAqD,CAAC;QAC1D,IAAI,UAAU,CAAC,qBAAqB,IAAI,IAAI,EAAE,CAAC;YAC7C,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC9D,IAAI,MAAM,CAAC,eAAe,IAAI,UAAU,CAAC,qBAAqB,EAAE,CAAC;oBAC/D,qBAAqB,GAAG,MAAM,CAAC;oBAC/B,MAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,IAAI,oBAAoB,CAAC;YAC9B,OAAO,EAAE,UAAU,CAAC,OAAO;YAC3B,SAAS;YACT,qBAAqB;SACtB,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,4BAA4B,GAAyB,IAAI,oBAAoB,CAAC;QACnF,OAAO,EAAE,oBAAoB,CAAC,MAAM;KACrC,CAAC,CAAC"}
@@ -30,6 +30,7 @@ export declare class ParameterLookup implements Equatable {
30
30
  equals(other: unknown): boolean;
31
31
  }
32
32
  export declare class EvaluateTableValuedFunction implements Equatable {
33
+ #private;
33
34
  readonly tableValuedFunction: TableValuedResultSet;
34
35
  readonly outputs: RowExpression[];
35
36
  readonly filters: RowExpression[];
@@ -1,4 +1,4 @@
1
- import { equalsIgnoringResultSetList, equalsIgnoringResultSetUnordered } from './compatibility.js';
1
+ import { TableValuedFunctionEquality } from './compatibility.js';
2
2
  import { HashSet, StableHasher, unorderedEquality } from './equality.js';
3
3
  /**
4
4
  * Describes how to resolve a subscription to buckets.
@@ -17,7 +17,7 @@ export class StreamResolver {
17
17
  this.uniqueName = uniqueName;
18
18
  }
19
19
  buildInstantiationHash(hasher) {
20
- equalsIgnoringResultSetUnordered.hash(hasher, this.requestFilters);
20
+ TableValuedFunctionEquality.empty.unorderedEquality.hash(hasher, this.requestFilters);
21
21
  StreamResolver.lookupStageEquality.hash(hasher, this.lookupStages);
22
22
  this.resolvedBucket.buildInstantiationHash(hasher);
23
23
  }
@@ -25,7 +25,7 @@ export class StreamResolver {
25
25
  if (other.options != this.options) {
26
26
  return false;
27
27
  }
28
- if (!equalsIgnoringResultSetUnordered.equals(other.requestFilters, this.requestFilters)) {
28
+ if (!TableValuedFunctionEquality.empty.unorderedEquality.equals(other.requestFilters, this.requestFilters)) {
29
29
  return false;
30
30
  }
31
31
  if (!StreamResolver.lookupStageEquality.equals(other.lookupStages, this.lookupStages)) {
@@ -68,21 +68,30 @@ export class EvaluateTableValuedFunction {
68
68
  tableValuedFunction;
69
69
  outputs;
70
70
  filters;
71
+ #hashes;
71
72
  constructor(tableValuedFunction, outputs, filters) {
72
73
  this.tableValuedFunction = tableValuedFunction;
73
74
  this.outputs = outputs;
74
75
  this.filters = filters;
76
+ this.#hashes = TableValuedFunctionEquality.forSingleTableValuedFunction(tableValuedFunction);
75
77
  }
76
78
  buildHash(hasher) {
77
- this.tableValuedFunction.buildBehaviorHashCode(hasher);
78
- equalsIgnoringResultSetList.hash(hasher, this.outputs);
79
- equalsIgnoringResultSetList.hash(hasher, this.filters);
79
+ this.tableValuedFunction.buildBehaviorHashCode(TableValuedFunctionEquality.empty, hasher);
80
+ this.#hashes.listEquality.hash(hasher, this.outputs);
81
+ this.#hashes.unorderedEquality.hash(hasher, this.filters);
80
82
  }
81
83
  equals(other) {
82
- return (other instanceof EvaluateTableValuedFunction &&
83
- other.tableValuedFunction.behavesIdenticalTo(this.tableValuedFunction) &&
84
- equalsIgnoringResultSetList.equals(other.outputs, this.outputs) &&
85
- equalsIgnoringResultSetList.equals(other.filters, this.filters));
84
+ if (!(other instanceof EvaluateTableValuedFunction) ||
85
+ !other.tableValuedFunction.behavesIdenticalTo(this.tableValuedFunction, TableValuedFunctionEquality.empty)) {
86
+ return false;
87
+ }
88
+ const symbolMap = new Map();
89
+ const symbol = Symbol();
90
+ symbolMap.set(this.tableValuedFunction, symbol);
91
+ symbolMap.set(other.tableValuedFunction, symbol);
92
+ const equality = TableValuedFunctionEquality.mergeForEquality(this.#hashes, other.#hashes, symbolMap);
93
+ return (equality.listEquality.equals(this.outputs, other.outputs) &&
94
+ equality.unorderedEquality.equals(this.filters, other.filters));
86
95
  }
87
96
  }
88
97
  export class ResolveBucket {
@@ -111,10 +120,11 @@ export class RequestParameterValue {
111
120
  this.expression = expression;
112
121
  }
113
122
  buildHash(hasher) {
114
- this.expression.assumingSameResultSetEqualityHashCode(hasher);
123
+ this.expression.assumingSamePrimaryResultSetEqualityHashCode(TableValuedFunctionEquality.empty, hasher);
115
124
  }
116
125
  equals(other) {
117
- return other instanceof RequestParameterValue && other.expression.equalsAssumingSameResultSet(this.expression);
126
+ return (other instanceof RequestParameterValue &&
127
+ this.expression.equalsAssumingSamePrimaryResultSet(other.expression, TableValuedFunctionEquality.empty));
118
128
  }
119
129
  }
120
130
  export class LookupResultParameterValue {
@@ -1 +1 @@
1
- {"version":3,"file":"bucket_resolver.js","sourceRoot":"","sources":["../../src/compiler/bucket_resolver.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,gCAAgC,EAAE,MAAM,oBAAoB,CAAC;AACnG,OAAO,EAAuB,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAK9F;;GAEG;AACH,MAAM,OAAO,cAAc;IAEd;IACA;IACA;IACA;IACA;IALX,YACW,OAAsB,EACtB,cAAmC,EACnC,YAAiC,EACjC,cAA6B,EAC7B,UAAkB;QAJlB,YAAO,GAAP,OAAO,CAAe;QACtB,mBAAc,GAAd,cAAc,CAAqB;QACnC,iBAAY,GAAZ,YAAY,CAAqB;QACjC,mBAAc,GAAd,cAAc,CAAe;QAC7B,eAAU,GAAV,UAAU,CAAQ;IAC1B,CAAC;IAEJ,sBAAsB,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,gBAAW,GAAX,WAAW,CAAQ;IAAG,CAAC;IAE5C,SAAS,CAAC,MAAoB;QAC5B,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QAC/B,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,CAAC,KAAqB;QAC1B,OAAO,CACL,KAAK,YAAY,0BAA0B;YAC3C,KAAK,CAAC,MAAO,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;YACjC,KAAK,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,CACtC,CAAC;IACJ,CAAC;CACF;AAED,MAAM,OAAO,0BAA0B;IAChB;IAArB,YAAqB,KAAuB;QAAvB,UAAK,GAAL,KAAK,CAAkB;IAAG,CAAC;IAEhD,SAAS,CAAC,MAAoB;QAC5B,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,KAAc;QACnB,OAAO,CACL,KAAK,YAAY,0BAA0B,IAAI,YAAY,CAAC,mBAAmB,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAChH,CAAC;IACJ,CAAC;CACF"}
@@ -1,16 +1,45 @@
1
1
  import { Equality, StableHasher } from './equality.js';
2
+ import { SourceResultSet, TableValuedResultSet } from './table.js';
2
3
  /**
3
- * Interface for structures that can be compared for equality in a way that ignores referenced result set.
4
+ * A semantic equality operator for syntactic structures.
4
5
  *
5
6
  * This is primarily used to compare expressions across streams. If we have two streams defined as
6
7
  * `SELECT * FROM users WHERE id = ...` , the `id` column would not be equal between those since it references a the
7
- * logical `users` table added to each individual statement. But if we are in a context where we know the physical table
8
- * is the same, this allows comparing expressions for equality.
8
+ * syntactical `users` table added to each individual statement. But if we are in a context where we know the resolved
9
+ * physical table is the same, this allows comparing expressions for equality.
10
+ *
11
+ * It is the responsibility of the caller to also check the primary result set (like `users` in this example) for
12
+ * equality before invoking these methods. Additionally, streams are allowed to join table-valued functions derived from
13
+ * the primary result set. Those must also be equal, which is why {@link TableValuedHashCodes} is used to generate
14
+ * stable hash codes for them and {@link TableValuedIdentities} guarantees that available table-valued functions have a
15
+ * 1:1 correspondence between compared structures.
9
16
  */
10
- export interface EqualsIgnoringResultSet {
11
- equalsAssumingSameResultSet(other: EqualsIgnoringResultSet): boolean;
12
- assumingSameResultSetEqualityHashCode(hasher: StableHasher): void;
17
+ export interface EqualsIgnoringPrimaryResultSet {
18
+ equalsAssumingSamePrimaryResultSet(other: EqualsIgnoringPrimaryResultSet, tableValued: TableValuedFunctionEquality): boolean;
19
+ assumingSamePrimaryResultSetEqualityHashCode(tableValued: TableValuedFunctionEquality, hasher: StableHasher): void;
20
+ }
21
+ interface ReadOnlyMap<K, V> {
22
+ get(key: K): V | undefined;
23
+ }
24
+ export declare class TableValuedFunctionEquality implements Equality<EqualsIgnoringPrimaryResultSet> {
25
+ #private;
26
+ private constructor();
27
+ get listEquality(): Equality<Iterable<EqualsIgnoringPrimaryResultSet>>;
28
+ get unorderedEquality(): Equality<Iterable<EqualsIgnoringPrimaryResultSet>>;
29
+ equals(a: EqualsIgnoringPrimaryResultSet, b: EqualsIgnoringPrimaryResultSet): boolean;
30
+ resultSetEquals(a: SourceResultSet, b: SourceResultSet): boolean;
31
+ hashResultSet(hasher: StableHasher, resultSet: SourceResultSet): void;
32
+ hash(hasher: StableHasher, value: EqualsIgnoringPrimaryResultSet): void;
33
+ /**
34
+ * An equality operator for table-valued functions, suitable only for generating hash codes within a single structure
35
+ * owning table-valued functions.
36
+ *
37
+ * This can't be used to compare functions across streams or to test for equality.
38
+ */
39
+ static forHashCode(innerHashes: ReadOnlyMap<TableValuedResultSet, number>): TableValuedFunctionEquality;
40
+ static forSingleTableValuedFunction(resultSet: TableValuedResultSet): TableValuedFunctionEquality;
41
+ static forSingleOwner(innerHashes: ReadOnlyMap<TableValuedResultSet, number>, equality: ReadOnlyMap<TableValuedResultSet, unknown>): TableValuedFunctionEquality;
42
+ static mergeForEquality(localHashes: TableValuedFunctionEquality, otherHashes: TableValuedFunctionEquality, equality: ReadOnlyMap<TableValuedResultSet, symbol>): TableValuedFunctionEquality;
43
+ static readonly empty: TableValuedFunctionEquality;
13
44
  }
14
- export declare const equalsIgnoringResultSet: Equality<EqualsIgnoringResultSet>;
15
- export declare const equalsIgnoringResultSetList: Equality<Iterable<EqualsIgnoringResultSet>>;
16
- export declare const equalsIgnoringResultSetUnordered: Equality<Iterable<EqualsIgnoringResultSet>>;
45
+ export {};
@@ -1,12 +1,82 @@
1
- import { listEquality } from './equality.js';
2
- export const equalsIgnoringResultSet = {
3
- equals: function (a, b) {
4
- return a.equalsAssumingSameResultSet(b);
5
- },
6
- hash: function (hasher, value) {
7
- return value.assumingSameResultSetEqualityHashCode(hasher);
8
- }
9
- };
10
- export const equalsIgnoringResultSetList = listEquality(equalsIgnoringResultSet);
11
- export const equalsIgnoringResultSetUnordered = listEquality(equalsIgnoringResultSet);
1
+ import { listEquality, unorderedEquality } from './equality.js';
2
+ import { PhysicalSourceResultSet } from './table.js';
3
+ export class TableValuedFunctionEquality {
4
+ #hashes;
5
+ #identities;
6
+ #ordered;
7
+ #unordered;
8
+ constructor(hashes, identities) {
9
+ this.#hashes = hashes;
10
+ this.#identities = identities;
11
+ }
12
+ get listEquality() {
13
+ return (this.#ordered ??= listEquality(this));
14
+ }
15
+ get unorderedEquality() {
16
+ return (this.#unordered ??= unorderedEquality(this));
17
+ }
18
+ #lookupIdentity(resultSet) {
19
+ const symbol = this.#identities.get(resultSet);
20
+ if (symbol == null) {
21
+ throw new Error('Unknown table-valued result set for equals');
22
+ }
23
+ return symbol;
24
+ }
25
+ equals(a, b) {
26
+ return a.equalsAssumingSamePrimaryResultSet(b, this);
27
+ }
28
+ resultSetEquals(a, b) {
29
+ // We don't need to compare primary result sets, those are assumed to be equal.
30
+ if (a instanceof PhysicalSourceResultSet) {
31
+ return b instanceof PhysicalSourceResultSet;
32
+ }
33
+ else if (b instanceof PhysicalSourceResultSet) {
34
+ return a instanceof PhysicalSourceResultSet;
35
+ }
36
+ return this.#lookupIdentity(a) === this.#lookupIdentity(b);
37
+ }
38
+ hashResultSet(hasher, resultSet) {
39
+ // There's only one primary result set which we ignore by design.
40
+ if (resultSet instanceof PhysicalSourceResultSet)
41
+ return;
42
+ const hash = this.#hashes.get(resultSet);
43
+ if (hash == null) {
44
+ throw new Error('Hashing unknown table-valued result set');
45
+ }
46
+ hasher.addHash(hash);
47
+ }
48
+ hash(hasher, value) {
49
+ return value.assumingSamePrimaryResultSetEqualityHashCode(this, hasher);
50
+ }
51
+ /**
52
+ * An equality operator for table-valued functions, suitable only for generating hash codes within a single structure
53
+ * owning table-valued functions.
54
+ *
55
+ * This can't be used to compare functions across streams or to test for equality.
56
+ */
57
+ static forHashCode(innerHashes) {
58
+ return this.forSingleOwner(innerHashes, {
59
+ // Compare by identity within the single owner.
60
+ get: (tableValued) => tableValued
61
+ });
62
+ }
63
+ static forSingleTableValuedFunction(resultSet) {
64
+ const hashCodeMap = new Map();
65
+ // Hash codes are only used to ensure column references to different table-valued functions generate different
66
+ // codes. Since there's just one, it can be an arbitrary value.
67
+ hashCodeMap.set(resultSet, 0);
68
+ return this.forHashCode(hashCodeMap);
69
+ }
70
+ static forSingleOwner(innerHashes, equality) {
71
+ return new TableValuedFunctionEquality(innerHashes, equality);
72
+ }
73
+ static mergeForEquality(localHashes, otherHashes, equality) {
74
+ return new TableValuedFunctionEquality({
75
+ get(key) {
76
+ return localHashes.#hashes.get(key) ?? otherHashes.#hashes.get(key);
77
+ }
78
+ }, equality);
79
+ }
80
+ static empty = new TableValuedFunctionEquality(new Map(), new Map());
81
+ }
12
82
  //# sourceMappingURL=compatibility.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compatibility.js","sourceRoot":"","sources":["../../src/compiler/compatibility.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,YAAY,EAAgB,MAAM,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MAAM,CAAC,4BAA4B,CAAC,SAA+B;QACjE,MAAM,WAAW,GAAG,IAAI,GAAG,EAAgC,CAAC;QAC5D,8GAA8G;QAC9G,+DAA+D;QAC/D,WAAW,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC;QAE9B,OAAO,IAAI,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,CAAC,cAAc,CACnB,WAAsD,EACtD,QAAoD;QAEpD,OAAO,IAAI,2BAA2B,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAChE,CAAC;IAED,MAAM,CAAC,gBAAgB,CACrB,WAAwC,EACxC,WAAwC,EACxC,QAAmD;QAEnD,OAAO,IAAI,2BAA2B,CACpC;YACE,GAAG,CAAC,GAAG;gBACL,OAAO,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACtE,CAAC;SACF,EACD,QAAQ,CACT,CAAC;IACJ,CAAC;IAED,MAAM,CAAU,KAAK,GAAG,IAAI,2BAA2B,CAAC,IAAI,GAAG,EAAE,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC"}
@@ -1,9 +1,11 @@
1
1
  import { NodeLocation, PGNode } from 'pgsql-ast-parser';
2
- import { StreamOptions, SyncPlan } from '../sync_plan/plan.js';
2
+ import { SqlRuleError } from '../errors.js';
3
+ import { CompiledEventDescriptor, StreamOptions, SyncPlan } from '../sync_plan/plan.js';
3
4
  import { SourceSchema } from '../types.js';
4
5
  import { StreamResolver } from './bucket_resolver.js';
5
- import { PointLookup, RowEvaluator } from './rows.js';
6
+ import { EventRowEvaluator, PointLookup, RowEvaluator } from './rows.js';
6
7
  import { CommonTableExpression, PreparedSubquery } from './sqlite.js';
8
+ import type { PhysicalSourceResultSet } from './table.js';
7
9
  export interface SyncStreamsCompilerOptions {
8
10
  /**
9
11
  * Used exclusively for linting against the given {@link schema}.
@@ -19,26 +21,33 @@ export interface SyncStreamsCompilerOptions {
19
21
  * streams across schema changes.
20
22
  */
21
23
  schema?: SourceSchema;
24
+ /**
25
+ * Whether event payload `WHERE` clauses are compiled and applied.
26
+ *
27
+ * This defaults to true. It is disabled for editions that cannot persist compiled event plans and when restoring
28
+ * event SQL that predates those plans, because the legacy evaluator parsed `WHERE` clauses but did not validate or
29
+ * evaluate them.
30
+ */
31
+ compileEventPayloadFilters?: boolean;
22
32
  }
23
33
  export interface ParseStreamOptions extends StreamOptions {
24
34
  warnOnDangerousParameter: boolean;
25
35
  }
26
36
  /**
27
- * State for compiling sync streams.
37
+ * State for compiling Sync Streams and replication events into a sync plan.
28
38
  *
29
- * The output of compiling all sync streams is a {@link SyncPlan}, a declarative description of the sync process that
30
- * can be serialized to bucket storage. The compiler stores a mutable intermediate representation that is essentially a
31
- * copy of the sync plan, except that we're using JavaScript classes with methods to compute hash codes and equality
32
- * relations. This allows the compiler to efficiently de-duplicate parameters and buckets.
39
+ * The compiler stores a mutable intermediate representation that is essentially a copy of the resulting
40
+ * {@link SyncPlan}. Stream compilation uses JavaScript classes with behavioral equality, while events use plain
41
+ * compiler records. Stream queries and event definitions remain separate within that model.
33
42
  *
34
- * Overall, the compilation process is as follows: Each data query for a stream is first parsed by
43
+ * The stream compilation process is as follows: Each data query for a stream is first parsed by
35
44
  * {@link StreamQueryParser} into a canonicalized intermediate representation (see that class for details).
36
45
  * Then, {@link QuerierGraphBuilder} analyzes a chain of `AND` expressions to identify parameters (as partition keys)
37
46
  * and their instantiation, as well as static filters that need to be added to reach row.
38
47
  */
39
48
  export declare class SyncStreamsCompiler {
40
49
  readonly options: SyncStreamsCompilerOptions;
41
- readonly output: CompiledStreamQueries;
50
+ readonly output: SyncPlanCompilerModel;
42
51
  private readonly locations;
43
52
  constructor(options: SyncStreamsCompilerOptions);
44
53
  /**
@@ -53,14 +62,35 @@ export declare class SyncStreamsCompiler {
53
62
  */
54
63
  commonTableExpression(sql: string, errors: ParsingErrorListener): PreparedSubquery | null;
55
64
  /**
56
- * Utility for compiling a sync stream.
65
+ * Utility for compiling a Sync Stream.
57
66
  *
58
67
  * @param options Name, priority and `auto_subscribe` state for the stream.
59
68
  */
60
69
  stream(options: ParseStreamOptions): IndividualSyncStreamCompiler;
70
+ /**
71
+ * Compiles the payload queries for a named replication event.
72
+ *
73
+ * Event queries intentionally support a smaller surface than stream queries: They must project and filter a single
74
+ * physical source table and cannot depend on request parameters, joins, subqueries or table-valued functions.
75
+ */
76
+ event(name: string): IndividualEventCompiler;
77
+ /**
78
+ * @returns A sync plan representing an immutable snapshot of the compiler output.
79
+ */
80
+ toSyncPlan(): SyncPlan;
61
81
  }
62
82
  /**
63
- * Utility for compiling a single sync stream.
83
+ * Compiles raw event definitions from legacy sync plans into the current plan representation.
84
+ *
85
+ * All definitions share one compiler to match normal sync-config compilation. Callers should reject fatal errors
86
+ * rather than carrying invalid legacy event evaluators into a {@link SyncPlan}.
87
+ */
88
+ export declare function compileEventDefinitions(definitions: Readonly<Record<string, readonly string[]>>, options: SyncStreamsCompilerOptions): {
89
+ events: CompiledEventDescriptor[];
90
+ errors: SqlRuleError[];
91
+ };
92
+ /**
93
+ * Utility for compiling a single Sync Stream.
64
94
  */
65
95
  export interface IndividualSyncStreamCompiler {
66
96
  /**
@@ -80,10 +110,16 @@ export interface IndividualSyncStreamCompiler {
80
110
  */
81
111
  finish(): void;
82
112
  }
113
+ export interface IndividualEventCompiler {
114
+ /**
115
+ * Validates and adds one payload query to this event.
116
+ */
117
+ addSourceQuery(sql: string, errors: ParsingErrorListener): void;
118
+ }
83
119
  /**
84
120
  * Something reporting errors.
85
121
  *
86
- * While sync streams can be made up of multiple SQL statements from different YAML strings, we want to be able to
122
+ * While Sync Streams can be made up of multiple SQL statements from different YAML strings, we want to be able to
87
123
  * accurately describe the source of an error in YAML when we report it.
88
124
  *
89
125
  * So, every transformation that might need to report errors receives an instance of this interface which implicitly
@@ -106,8 +142,40 @@ export declare class CompiledStreamQueries {
106
142
  get pointLookups(): PointLookup[];
107
143
  canonicalizeEvaluator(evaluator: RowEvaluator): RowEvaluator;
108
144
  canonicalizePointLookup(lookup: PointLookup): PointLookup;
109
- /**
110
- * @returns A sync plan representing an immutable snapshot of this intermediate representation.
111
- */
112
- toSyncPlan(): SyncPlan;
145
+ }
146
+ /**
147
+ * Compiler model for one SQL query in a named event's `payloads` list.
148
+ *
149
+ * It binds that query to its single physical source table and contains one row evaluator for each normalized `OR`
150
+ * branch. Within each evaluator, filters determine whether a source row triggers the event, while projected columns
151
+ * determine the payload produced for a matching row.
152
+ *
153
+ * {@link sql} is retained so service-core can dual-write the legacy `eventDescriptors` field for older services during
154
+ * rolling upgrades. The executable plan uses the parsed source table and row evaluators instead.
155
+ */
156
+ export interface CompiledEventSourceQueryModel {
157
+ sql: string;
158
+ sourceTable: PhysicalSourceResultSet;
159
+ variants: EventRowEvaluator[];
160
+ }
161
+ /**
162
+ * Compiler model for one named entry under `event_definitions`.
163
+ *
164
+ * {@link name} identifies the event exposed to handlers. {@link sourceQueries} represents its complete `payloads`
165
+ * list, which may define how rows from different source tables trigger that event and produce its payload.
166
+ */
167
+ export interface CompiledEvent {
168
+ name: string;
169
+ sourceQueries: CompiledEventSourceQueryModel[];
170
+ }
171
+ /**
172
+ * Top-level compiler output used to assemble a complete sync plan.
173
+ *
174
+ * Streams and events are sibling sync-config concerns. Keeping their intermediate state separate prevents stream
175
+ * compilation abstractions from acquiring event-specific responsibilities just because both are persisted in one
176
+ * {@link SyncPlan}.
177
+ */
178
+ export interface SyncPlanCompilerModel {
179
+ readonly streams: CompiledStreamQueries;
180
+ readonly events: CompiledEvent[];
113
181
  }