powersync 0.1.0 → 0.1.2

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 (191) hide show
  1. package/README.md +14 -14
  2. package/dist/commands/init.d.ts +0 -1
  3. package/dist/commands/init.js +11 -8
  4. package/dist/commands/instance/sync-rules/generate-schema.js +6 -6
  5. package/dist/constants.d.ts +2 -5
  6. package/dist/constants.js +4 -2
  7. package/dist/service/accounts.client.js +11129 -25
  8. package/dist/service/powersync.client.js +37453 -113
  9. package/dist/service/types.js +1 -1
  10. package/dist/service/utils.js +6 -6
  11. package/dist/utils.js +5 -7
  12. package/oclif.manifest.json +1 -1
  13. package/package.json +28 -20
  14. package/dist/powersync-sdk/accounts/api.d.ts +0 -717
  15. package/dist/powersync-sdk/accounts/api.js +0 -182
  16. package/dist/powersync-sdk/accounts/client.d.ts +0 -1096
  17. package/dist/powersync-sdk/accounts/client.js +0 -124
  18. package/dist/powersync-sdk/accounts/codecs.d.ts +0 -32
  19. package/dist/powersync-sdk/accounts/codecs.js +0 -93
  20. package/dist/powersync-sdk/accounts/index.d.ts +0 -4
  21. package/dist/powersync-sdk/accounts/index.js +0 -4
  22. package/dist/powersync-sdk/accounts/models.d.ts +0 -260
  23. package/dist/powersync-sdk/accounts/models.js +0 -96
  24. package/dist/powersync-sdk/accounts/routes.d.ts +0 -44
  25. package/dist/powersync-sdk/accounts/routes.js +0 -45
  26. package/dist/powersync-sdk/accounts/source.d.ts +0 -76
  27. package/dist/powersync-sdk/accounts/source.js +0 -32
  28. package/dist/powersync-sdk/errors/errors.d.ts +0 -62
  29. package/dist/powersync-sdk/errors/errors.js +0 -115
  30. package/dist/powersync-sdk/errors/index.d.ts +0 -2
  31. package/dist/powersync-sdk/errors/index.js +0 -2
  32. package/dist/powersync-sdk/errors/utils.d.ts +0 -4
  33. package/dist/powersync-sdk/errors/utils.js +0 -18
  34. package/dist/powersync-sdk/fetch-clients/codecs.d.ts +0 -4
  35. package/dist/powersync-sdk/fetch-clients/codecs.js +0 -34
  36. package/dist/powersync-sdk/fetch-clients/decoders.d.ts +0 -3
  37. package/dist/powersync-sdk/fetch-clients/decoders.js +0 -35
  38. package/dist/powersync-sdk/fetch-clients/definitions.d.ts +0 -97
  39. package/dist/powersync-sdk/fetch-clients/definitions.js +0 -22
  40. package/dist/powersync-sdk/fetch-clients/errors.d.ts +0 -7
  41. package/dist/powersync-sdk/fetch-clients/errors.js +0 -19
  42. package/dist/powersync-sdk/fetch-clients/index.d.ts +0 -5
  43. package/dist/powersync-sdk/fetch-clients/index.js +0 -5
  44. package/dist/powersync-sdk/fetch-clients/node-client.d.ts +0 -9
  45. package/dist/powersync-sdk/fetch-clients/node-client.js +0 -107
  46. package/dist/powersync-sdk/fetch-clients/request.d.ts +0 -11
  47. package/dist/powersync-sdk/fetch-clients/request.js +0 -138
  48. package/dist/powersync-sdk/fetch-clients/streaming.d.ts +0 -65
  49. package/dist/powersync-sdk/fetch-clients/streaming.js +0 -99
  50. package/dist/powersync-sdk/fetch-clients/utils.d.ts +0 -13
  51. package/dist/powersync-sdk/fetch-clients/utils.js +0 -43
  52. package/dist/powersync-sdk/fetch-clients/web-client.d.ts +0 -14
  53. package/dist/powersync-sdk/fetch-clients/web-client.js +0 -56
  54. package/dist/powersync-sdk/json/index.d.ts +0 -4
  55. package/dist/powersync-sdk/json/index.js +0 -3
  56. package/dist/powersync-sdk/json/json.d.ts +0 -5
  57. package/dist/powersync-sdk/json/json.js +0 -35
  58. package/dist/powersync-sdk/json/json_container.d.ts +0 -18
  59. package/dist/powersync-sdk/json/json_container.js +0 -28
  60. package/dist/powersync-sdk/json/json_stringify.d.ts +0 -36
  61. package/dist/powersync-sdk/json/json_stringify.js +0 -162
  62. package/dist/powersync-sdk/powersync/client.d.ts +0 -449
  63. package/dist/powersync-sdk/powersync/client.js +0 -53
  64. package/dist/powersync-sdk/powersync/config/HostedConfig.d.ts +0 -327
  65. package/dist/powersync-sdk/powersync/config/HostedConfig.js +0 -92
  66. package/dist/powersync-sdk/powersync/config/PowerSyncConfig.d.ts +0 -211
  67. package/dist/powersync-sdk/powersync/config/PowerSyncConfig.js +0 -97
  68. package/dist/powersync-sdk/powersync/config/normalize.d.ts +0 -32
  69. package/dist/powersync-sdk/powersync/config/normalize.js +0 -85
  70. package/dist/powersync-sdk/powersync/definitions.d.ts +0 -149
  71. package/dist/powersync-sdk/powersync/definitions.js +0 -97
  72. package/dist/powersync-sdk/powersync/index.d.ts +0 -8
  73. package/dist/powersync-sdk/powersync/index.js +0 -8
  74. package/dist/powersync-sdk/powersync/internal_routes.d.ts +0 -247
  75. package/dist/powersync-sdk/powersync/internal_routes.js +0 -69
  76. package/dist/powersync-sdk/powersync/routes.d.ts +0 -779
  77. package/dist/powersync-sdk/powersync/routes.js +0 -191
  78. package/dist/powersync-sdk/sdk-clients/endpoints.d.ts +0 -31
  79. package/dist/powersync-sdk/sdk-clients/endpoints.js +0 -48
  80. package/dist/powersync-sdk/sdk-clients/index.d.ts +0 -3
  81. package/dist/powersync-sdk/sdk-clients/index.js +0 -3
  82. package/dist/powersync-sdk/sdk-clients/pagination.d.ts +0 -14
  83. package/dist/powersync-sdk/sdk-clients/pagination.js +0 -21
  84. package/dist/powersync-sdk/sdk-clients/sdk-client.d.ts +0 -17
  85. package/dist/powersync-sdk/sdk-clients/sdk-client.js +0 -30
  86. package/dist/powersync-sdk/streaming/bson/buffer-array.d.ts +0 -31
  87. package/dist/powersync-sdk/streaming/bson/buffer-array.js +0 -79
  88. package/dist/powersync-sdk/streaming/bson/constants.d.ts +0 -2
  89. package/dist/powersync-sdk/streaming/bson/constants.js +0 -1
  90. package/dist/powersync-sdk/streaming/bson/decoder.d.ts +0 -10
  91. package/dist/powersync-sdk/streaming/bson/decoder.js +0 -62
  92. package/dist/powersync-sdk/streaming/bson/encoder.d.ts +0 -10
  93. package/dist/powersync-sdk/streaming/bson/encoder.js +0 -23
  94. package/dist/powersync-sdk/streaming/bson/header.d.ts +0 -11
  95. package/dist/powersync-sdk/streaming/bson/header.js +0 -52
  96. package/dist/powersync-sdk/streaming/bson/index.d.ts +0 -5
  97. package/dist/powersync-sdk/streaming/bson/index.js +0 -5
  98. package/dist/powersync-sdk/streaming/core/backpressure.d.ts +0 -15
  99. package/dist/powersync-sdk/streaming/core/backpressure.js +0 -34
  100. package/dist/powersync-sdk/streaming/core/cross-stream.d.ts +0 -6
  101. package/dist/powersync-sdk/streaming/core/cross-stream.js +0 -17
  102. package/dist/powersync-sdk/streaming/core/index.d.ts +0 -4
  103. package/dist/powersync-sdk/streaming/core/index.js +0 -4
  104. package/dist/powersync-sdk/streaming/core/node-utils.d.ts +0 -7
  105. package/dist/powersync-sdk/streaming/core/node-utils.js +0 -11
  106. package/dist/powersync-sdk/streaming/core/transformers.d.ts +0 -41
  107. package/dist/powersync-sdk/streaming/core/transformers.js +0 -70
  108. package/dist/powersync-sdk/streaming/core/utils.d.ts +0 -36
  109. package/dist/powersync-sdk/streaming/core/utils.js +0 -66
  110. package/dist/powersync-sdk/streaming/index.d.ts +0 -3
  111. package/dist/powersync-sdk/streaming/index.js +0 -3
  112. package/dist/powersync-sdk/streaming/web.d.ts +0 -4
  113. package/dist/powersync-sdk/streaming/web.js +0 -4
  114. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binaryreader.d.ts +0 -2
  115. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binaryreader.js +0 -36
  116. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binarywriter.d.ts +0 -2
  117. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/binarywriter.js +0 -58
  118. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometry.d.ts +0 -18
  119. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometry.js +0 -348
  120. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometrycollection.d.ts +0 -11
  121. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/geometrycollection.js +0 -118
  122. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/linestring.d.ts +0 -11
  123. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/linestring.js +0 -131
  124. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multilinestring.d.ts +0 -11
  125. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multilinestring.js +0 -134
  126. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipoint.d.ts +0 -11
  127. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipoint.js +0 -122
  128. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipolygon.d.ts +0 -11
  129. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/multipolygon.js +0 -158
  130. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/point.d.ts +0 -14
  131. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/point.js +0 -165
  132. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/polygon.d.ts +0 -11
  133. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/polygon.js +0 -207
  134. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/types.d.ts +0 -30
  135. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/types.js +0 -29
  136. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wktparser.d.ts +0 -2
  137. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wktparser.js +0 -111
  138. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wkx.d.ts +0 -9
  139. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/wkx.js +0 -9
  140. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/zigzag.d.ts +0 -5
  141. package/dist/powersync-sdk/sync-rules/@syncpoint/wkx/zigzag.js +0 -9
  142. package/dist/powersync-sdk/sync-rules/DartSchemaGenerator.d.ts +0 -12
  143. package/dist/powersync-sdk/sync-rules/DartSchemaGenerator.js +0 -35
  144. package/dist/powersync-sdk/sync-rules/ExpressionType.d.ts +0 -33
  145. package/dist/powersync-sdk/sync-rules/ExpressionType.js +0 -62
  146. package/dist/powersync-sdk/sync-rules/IdSequence.d.ts +0 -4
  147. package/dist/powersync-sdk/sync-rules/IdSequence.js +0 -7
  148. package/dist/powersync-sdk/sync-rules/JsSchemaGenerator.d.ts +0 -12
  149. package/dist/powersync-sdk/sync-rules/JsSchemaGenerator.js +0 -38
  150. package/dist/powersync-sdk/sync-rules/SchemaGenerator.d.ts +0 -14
  151. package/dist/powersync-sdk/sync-rules/SchemaGenerator.js +0 -24
  152. package/dist/powersync-sdk/sync-rules/SourceTableInterface.d.ts +0 -5
  153. package/dist/powersync-sdk/sync-rules/SourceTableInterface.js +0 -1
  154. package/dist/powersync-sdk/sync-rules/SqlBucketDescriptor.d.ts +0 -37
  155. package/dist/powersync-sdk/sync-rules/SqlBucketDescriptor.js +0 -116
  156. package/dist/powersync-sdk/sync-rules/SqlDataQuery.d.ts +0 -39
  157. package/dist/powersync-sdk/sync-rules/SqlDataQuery.js +0 -245
  158. package/dist/powersync-sdk/sync-rules/SqlParameterQuery.d.ts +0 -43
  159. package/dist/powersync-sdk/sync-rules/SqlParameterQuery.js +0 -254
  160. package/dist/powersync-sdk/sync-rules/SqlSyncRules.d.ts +0 -52
  161. package/dist/powersync-sdk/sync-rules/SqlSyncRules.js +0 -252
  162. package/dist/powersync-sdk/sync-rules/StaticSchema.d.ts +0 -26
  163. package/dist/powersync-sdk/sync-rules/StaticSchema.js +0 -71
  164. package/dist/powersync-sdk/sync-rules/StaticSqlParameterQuery.d.ts +0 -24
  165. package/dist/powersync-sdk/sync-rules/StaticSqlParameterQuery.js +0 -71
  166. package/dist/powersync-sdk/sync-rules/TablePattern.d.ts +0 -17
  167. package/dist/powersync-sdk/sync-rules/TablePattern.js +0 -56
  168. package/dist/powersync-sdk/sync-rules/TableQuerySchema.d.ts +0 -9
  169. package/dist/powersync-sdk/sync-rules/TableQuerySchema.js +0 -41
  170. package/dist/powersync-sdk/sync-rules/errors.d.ts +0 -22
  171. package/dist/powersync-sdk/sync-rules/errors.js +0 -60
  172. package/dist/powersync-sdk/sync-rules/generators.d.ts +0 -6
  173. package/dist/powersync-sdk/sync-rules/generators.js +0 -6
  174. package/dist/powersync-sdk/sync-rules/index.d.ts +0 -17
  175. package/dist/powersync-sdk/sync-rules/index.js +0 -17
  176. package/dist/powersync-sdk/sync-rules/json_schema.d.ts +0 -3
  177. package/dist/powersync-sdk/sync-rules/json_schema.js +0 -50
  178. package/dist/powersync-sdk/sync-rules/sql_filters.d.ts +0 -91
  179. package/dist/powersync-sdk/sync-rules/sql_filters.js +0 -491
  180. package/dist/powersync-sdk/sync-rules/sql_functions.d.ts +0 -53
  181. package/dist/powersync-sdk/sync-rules/sql_functions.js +0 -755
  182. package/dist/powersync-sdk/sync-rules/sql_support.d.ts +0 -22
  183. package/dist/powersync-sdk/sync-rules/sql_support.js +0 -208
  184. package/dist/powersync-sdk/sync-rules/types.d.ts +0 -174
  185. package/dist/powersync-sdk/sync-rules/types.js +0 -9
  186. package/dist/powersync-sdk/sync-rules/utils.d.ts +0 -45
  187. package/dist/powersync-sdk/sync-rules/utils.js +0 -163
  188. package/dist/service/accounts.client.d.ts +0 -26
  189. package/dist/service/powersync.client.d.ts +0 -269
  190. package/dist/service/types.d.ts +0 -69
  191. package/dist/service/utils.d.ts +0 -5
@@ -1,22 +0,0 @@
1
- import { SelectFromStatement } from 'pgsql-ast-parser';
2
- import { SqlRuleError } from './errors.js';
3
- import { ClauseError, CompiledClause, ParameterMatchClause, ParameterValueClause, SqliteValue, StaticRowValueClause } from './types.js';
4
- export declare function isParameterMatchClause(clause: CompiledClause): clause is ParameterMatchClause;
5
- export declare function isStaticRowValueClause(clause: CompiledClause): clause is StaticRowValueClause;
6
- export declare function isParameterValueClause(clause: CompiledClause): clause is ParameterValueClause;
7
- export declare function isClauseError(clause: CompiledClause): clause is ClauseError;
8
- export declare const SQLITE_TRUE = 1n;
9
- export declare const SQLITE_FALSE = 0n;
10
- export declare function sqliteBool(value: SqliteValue | boolean): 0n | 1n;
11
- export declare function sqliteNot(value: SqliteValue | boolean): 0n | 1n;
12
- export declare function compileStaticOperator(op: string, left: StaticRowValueClause, right: StaticRowValueClause): StaticRowValueClause;
13
- export declare function andFilters(a: CompiledClause, b: CompiledClause): CompiledClause;
14
- export declare function orFilters(a: CompiledClause, b: CompiledClause): CompiledClause;
15
- export declare function orParameterSetClauses(a: ParameterMatchClause, b: ParameterMatchClause): ParameterMatchClause;
16
- /**
17
- * Given any CompiledClause, convert it into a ParameterMatchClause.
18
- *
19
- * @param clause
20
- */
21
- export declare function toBooleanParameterSetClause(clause: CompiledClause): ParameterMatchClause;
22
- export declare function checkUnsupportedFeatures(sql: string, q: SelectFromStatement): SqlRuleError[];
@@ -1,208 +0,0 @@
1
- import { ExpressionType } from './ExpressionType.js';
2
- import { SqlRuleError } from './errors.js';
3
- import { MATCH_CONST_FALSE, MATCH_CONST_TRUE } from './sql_filters.js';
4
- import { evaluateOperator, getOperatorReturnType } from './sql_functions.js';
5
- export function isParameterMatchClause(clause) {
6
- return Array.isArray(clause.bucketParameters);
7
- }
8
- export function isStaticRowValueClause(clause) {
9
- return typeof clause.evaluate === 'function';
10
- }
11
- export function isParameterValueClause(clause) {
12
- // noinspection SuspiciousTypeOfGuard
13
- return typeof clause.bucketParameter === 'string';
14
- }
15
- export function isClauseError(clause) {
16
- return clause.error === true;
17
- }
18
- export const SQLITE_TRUE = 1n;
19
- export const SQLITE_FALSE = 0n;
20
- export function sqliteBool(value) {
21
- if (value == null) {
22
- return SQLITE_FALSE;
23
- }
24
- if (typeof value === 'boolean' || typeof value === 'number') {
25
- return value ? SQLITE_TRUE : SQLITE_FALSE;
26
- }
27
- if (typeof value === 'bigint') {
28
- return value == 0n ? SQLITE_FALSE : SQLITE_TRUE;
29
- }
30
- if (typeof value === 'string') {
31
- return Number.parseInt(value) ? SQLITE_TRUE : SQLITE_FALSE;
32
- }
33
- return SQLITE_FALSE;
34
- }
35
- export function sqliteNot(value) {
36
- return sqliteBool(!sqliteBool(value));
37
- }
38
- export function compileStaticOperator(op, left, right) {
39
- return {
40
- evaluate(tables) {
41
- const leftValue = left.evaluate(tables);
42
- const rightValue = right.evaluate(tables);
43
- return evaluateOperator(op, leftValue, rightValue);
44
- },
45
- getType(schema) {
46
- const typeLeft = left.getType(schema);
47
- const typeRight = right.getType(schema);
48
- return getOperatorReturnType(op, typeLeft, typeRight);
49
- }
50
- };
51
- }
52
- export function andFilters(a, b) {
53
- if (isStaticRowValueClause(a) && isStaticRowValueClause(b)) {
54
- // Optimization
55
- return {
56
- evaluate(tables) {
57
- const aValue = sqliteBool(a.evaluate(tables));
58
- const bValue = sqliteBool(b.evaluate(tables));
59
- return sqliteBool(aValue && bValue);
60
- },
61
- getType() {
62
- return ExpressionType.INTEGER;
63
- }
64
- };
65
- }
66
- const aFilter = toBooleanParameterSetClause(a);
67
- const bFilter = toBooleanParameterSetClause(b);
68
- const aParams = aFilter.bucketParameters;
69
- const bParams = bFilter.bucketParameters;
70
- if (aFilter.unbounded && bFilter.unbounded) {
71
- // This could explode the number of buckets for the row
72
- throw new Error('Cannot have multiple IN expressions on bucket parameters');
73
- }
74
- const combined = new Set([...aParams, ...bParams]);
75
- return {
76
- bucketParameters: [...combined],
77
- error: aFilter.error || bFilter.error,
78
- filter(tables) {
79
- const aResult = aFilter.filter(tables);
80
- const bResult = bFilter.filter(tables);
81
- const results = [];
82
- for (const result1 of aResult) {
83
- for (const result2 of bResult) {
84
- const combined = { ...result1 };
85
- let valid = true;
86
- for (const key in result2) {
87
- if (key in combined && combined[key] != result2[key]) {
88
- valid = false;
89
- break;
90
- }
91
- combined[key] = result2[key];
92
- }
93
- results.push(combined);
94
- }
95
- }
96
- return results;
97
- },
98
- unbounded: aFilter.unbounded || bFilter.unbounded // result count = a.count * b.count
99
- };
100
- }
101
- export function orFilters(a, b) {
102
- if (isStaticRowValueClause(a) && isStaticRowValueClause(b)) {
103
- // Optimization
104
- return {
105
- evaluate(tables) {
106
- const aValue = sqliteBool(a.evaluate(tables));
107
- const bValue = sqliteBool(b.evaluate(tables));
108
- return sqliteBool(aValue || bValue);
109
- },
110
- getType() {
111
- return ExpressionType.INTEGER;
112
- }
113
- };
114
- }
115
- const aFilter = toBooleanParameterSetClause(a);
116
- const bFilter = toBooleanParameterSetClause(b);
117
- return orParameterSetClauses(aFilter, bFilter);
118
- }
119
- export function orParameterSetClauses(a, b) {
120
- const aParams = a.bucketParameters;
121
- const bParams = b.bucketParameters;
122
- // This gives the guaranteed set of parameters matched against.
123
- const allParams = new Set([...aParams, ...bParams]);
124
- if (allParams.size != aParams.length || allParams.size != bParams.length) {
125
- throw new Error(`Left and right sides of OR must use the same parameters, or split into separate queries. ${JSON.stringify(aParams)} != ${JSON.stringify(bParams)}`);
126
- }
127
- const parameters = [...allParams];
128
- // assets.region_id = bucket.region_id AND bucket.user_id IN assets.user_ids
129
- // OR bucket.region_id IN assets.region_ids AND bucket.user_id = assets.user_id
130
- const unbounded = a.unbounded || b.unbounded;
131
- return {
132
- bucketParameters: parameters,
133
- error: a.error || b.error,
134
- filter(tables) {
135
- const aResult = a.filter(tables);
136
- const bResult = b.filter(tables);
137
- const results = [...aResult, ...bResult];
138
- return results;
139
- },
140
- unbounded // result count = a.count + b.count
141
- };
142
- }
143
- /**
144
- * Given any CompiledClause, convert it into a ParameterMatchClause.
145
- *
146
- * @param clause
147
- */
148
- export function toBooleanParameterSetClause(clause) {
149
- if (isParameterMatchClause(clause)) {
150
- return clause;
151
- }
152
- if (isStaticRowValueClause(clause)) {
153
- return {
154
- bucketParameters: [],
155
- error: false,
156
- filter(tables) {
157
- const value = sqliteBool(clause.evaluate(tables));
158
- return value ? MATCH_CONST_TRUE : MATCH_CONST_FALSE;
159
- },
160
- unbounded: false
161
- };
162
- }
163
- if (isClauseError(clause)) {
164
- return {
165
- bucketParameters: [],
166
- error: true,
167
- filter(tables) {
168
- throw new Error('invalid clause');
169
- },
170
- unbounded: false
171
- };
172
- }
173
- // Equivalent to `bucket.param = true`
174
- const param = clause.bucketParameter;
175
- return {
176
- bucketParameters: [param],
177
- error: false,
178
- filter(tables) {
179
- return [{ [param]: SQLITE_TRUE }];
180
- },
181
- unbounded: false
182
- };
183
- }
184
- export function checkUnsupportedFeatures(sql, q) {
185
- const errors = [];
186
- if (q.limit != null) {
187
- errors.push(new SqlRuleError('LIMIT is not supported', sql, q.limit._location));
188
- }
189
- if (q.orderBy != null) {
190
- errors.push(new SqlRuleError('ORDER BY is not supported', sql, q.orderBy[0]?._location));
191
- }
192
- if (q.skip != null) {
193
- errors.push(new SqlRuleError('SKIP is not supported', sql, q.skip._location));
194
- }
195
- if (q.having != null) {
196
- errors.push(new SqlRuleError('HAVING is not supported', sql, q.having._location));
197
- }
198
- if (q.groupBy != null) {
199
- errors.push(new SqlRuleError('GROUP BY is not supported', sql, q.groupBy[0]?._location));
200
- }
201
- if (q.distinct != null) {
202
- errors.push(new SqlRuleError('DISTINCT is not supported', sql));
203
- }
204
- if (q.for != null) {
205
- errors.push(new SqlRuleError('SELECT FOR is not supported', sql, q.for._location));
206
- }
207
- return errors;
208
- }
@@ -1,174 +0,0 @@
1
- import { JsonContainer } from '../json/index.js';
2
- import { ColumnDefinition, ExpressionType } from './ExpressionType.js';
3
- import { SourceTableInterface } from './SourceTableInterface.js';
4
- import { TablePattern } from './TablePattern.js';
5
- export interface SyncRules {
6
- evaluateParameterRow(table: SourceTableInterface, row: SqliteRow): EvaluatedParametersResult[];
7
- evaluateRow(options: EvaluateRowOptions): EvaluationResult[];
8
- }
9
- export interface EvaluatedParameters {
10
- /**
11
- * Parameters used to generate bucket id. May be incomplete.
12
- *
13
- * JSON-serializable.
14
- */
15
- bucket_parameters: Record<string, SqliteJsonValue>[];
16
- lookup: SqliteJsonValue[];
17
- }
18
- export type EvaluatedParametersResult = EvaluatedParameters | EvaluationError;
19
- export interface EvaluatedRow {
20
- bucket: string;
21
- /** Must be JSON-serializable. */
22
- data: SqliteJsonRow;
23
- /**
24
- * Convenience attribute. Must match data.id.
25
- */
26
- id: string;
27
- /** For debugging purposes only. */
28
- ruleId?: string;
29
- /** Output table - may be different from input table. */
30
- table: string;
31
- }
32
- export interface EvaluationError {
33
- error: string;
34
- }
35
- export declare function isEvaluationError(e: any): e is EvaluationError;
36
- export declare function isEvaluatedRow(e: EvaluationResult): e is EvaluatedRow;
37
- export declare function isEvaluatedParameters(e: EvaluatedParametersResult): e is EvaluatedParameters;
38
- export type EvaluationResult = EvaluatedRow | EvaluationError;
39
- export interface SyncParameters {
40
- token_parameters: SqliteJsonRow;
41
- user_parameters: SqliteJsonRow;
42
- }
43
- /**
44
- * A value that is both SQLite and JSON-compatible.
45
- *
46
- * Uint8Array is not supported.
47
- */
48
- export type SqliteJsonValue = bigint | null | number | string;
49
- /**
50
- * A value supported by the SQLite type system.
51
- */
52
- export type SqliteValue = Uint8Array | bigint | null | number | string;
53
- /**
54
- * A set of values that are both SQLite and JSON-compatible.
55
- *
56
- * This is a flat object -> no nested arrays or objects.
57
- */
58
- export type SqliteJsonRow = {
59
- [column: string]: SqliteJsonValue;
60
- };
61
- /**
62
- * SQLite-compatible row (NULL, TEXT, INTEGER, REAL, BLOB).
63
- * JSON is represented as TEXT.
64
- */
65
- export type SqliteRow = {
66
- [column: string]: SqliteValue;
67
- };
68
- /**
69
- * SQLite-compatible row (NULL, TEXT, INTEGER, REAL, BLOB).
70
- * JSON is represented as TEXT.
71
- *
72
- * Toasted values are `undefined`.
73
- */
74
- export type ToastableSqliteRow = {
75
- [column: string]: SqliteValue | undefined;
76
- };
77
- /**
78
- * A value as received from the database.
79
- */
80
- export type DatabaseInputValue = {
81
- [key: string]: DatabaseInputValue;
82
- } | DatabaseInputValue[] | JsonContainer | SqliteValue | boolean;
83
- /**
84
- * Database input row. Can contain nested arrays and objects.
85
- */
86
- export type DatabaseInputRow = {
87
- [column: string]: DatabaseInputValue;
88
- };
89
- /**
90
- * A set of known parameters that a query is evaluated on.
91
- */
92
- export type QueryParameters = {
93
- [table: string]: SqliteRow;
94
- };
95
- /**
96
- * A single set of parameters that would make a WHERE filter true.
97
- *
98
- * Each parameter is prefixed with a table name, e.g. 'bucket.param'.
99
- */
100
- export type FilterParameters = {
101
- [parameter: string]: SqliteJsonValue;
102
- };
103
- export interface EvaluateRowOptions {
104
- record: SqliteRow;
105
- sourceTable: SourceTableInterface;
106
- }
107
- /**
108
- * Given a row, produces a set of parameters that would make the clause evaluate to true.
109
- */
110
- export interface ParameterMatchClause {
111
- /**
112
- * The parameter fields that are used for this filter, for example:
113
- * * ['bucket.region_id'] for a data query
114
- * * ['token_parameters.user_id'] for a parameter query
115
- *
116
- * These parameters are always matched by this clause, and no additional parameters are matched.
117
- */
118
- bucketParameters: string[];
119
- error: boolean;
120
- /**
121
- * Given a data row, give a set of filter parameters that would make the filter be true.
122
- *
123
- * @param tables - {table => row}
124
- * @return The filter parameters
125
- */
126
- filter(tables: QueryParameters): TrueIfParametersMatch;
127
- /**
128
- * True if the filter depends on an unbounded array column.
129
- *
130
- * We restrict filters to only allow a single unbounded column for bucket parameters, otherwise the number of
131
- * bucketParameter combinations could grow too much.
132
- */
133
- unbounded: boolean;
134
- }
135
- /**
136
- * Given a row, produces a set of parameters that would make the clause evaluate to true.
137
- */
138
- export interface ParameterValueClause {
139
- /**
140
- * The parameter fields used for this, e.g. 'bucket.region_id'
141
- */
142
- bucketParameter: string;
143
- }
144
- export interface QuerySchema {
145
- getColumns(table: string): ColumnDefinition[];
146
- getType(table: string, column: string): ExpressionType;
147
- }
148
- /**
149
- * Only needs row values as input, producing a static value as output.
150
- */
151
- export interface StaticRowValueClause {
152
- evaluate(tables: QueryParameters): SqliteValue;
153
- getType(schema: QuerySchema): ExpressionType;
154
- }
155
- export interface ClauseError {
156
- error: true;
157
- }
158
- export type CompiledClause = ClauseError | ParameterMatchClause | ParameterValueClause | StaticRowValueClause;
159
- /**
160
- * true if any of the filter parameter sets match
161
- */
162
- export type TrueIfParametersMatch = FilterParameters[];
163
- export interface QueryBucketIdOptions {
164
- getParameterSets: (lookups: SqliteJsonValue[][]) => Promise<SqliteJsonRow[]>;
165
- parameters: SyncParameters;
166
- }
167
- export interface SourceSchemaTable {
168
- getColumns(): ColumnDefinition[];
169
- getType(column: string): ExpressionType | undefined;
170
- table: string;
171
- }
172
- export interface SourceSchema {
173
- getTables(sourceTable: TablePattern): SourceSchemaTable[];
174
- }
@@ -1,9 +0,0 @@
1
- export function isEvaluationError(e) {
2
- return typeof e.error === 'string';
3
- }
4
- export function isEvaluatedRow(e) {
5
- return typeof e.bucket === 'string';
6
- }
7
- export function isEvaluatedParameters(e) {
8
- return Array.isArray(e.lookup);
9
- }
@@ -1,45 +0,0 @@
1
- import { SelectFromStatement, Statement } from 'pgsql-ast-parser';
2
- import { Replacer } from '../json/index.js';
3
- import { DatabaseInputRow, SqliteJsonRow, SqliteJsonValue, SqliteRow, SqliteValue, SyncParameters } from './types.js';
4
- export declare function isSelectStatement(q: Statement): q is SelectFromStatement;
5
- export declare function getBucketId(descriptor_id: string, bucket_parameters: string[], params: Record<string, SqliteJsonValue>): string;
6
- /**
7
- * SqliteRow -> SqliteJsonRow.
8
- *
9
- * Use wherever data should be persisted.
10
- *
11
- * Basically just removes Uint8Array.
12
- */
13
- export declare function filterJsonRow(data: SqliteRow): SqliteJsonRow;
14
- /**
15
- * Convert a parsed JSON scalar value to SqliteValue.
16
- *
17
- * Types specifically not supported in output are `boolean` and `undefined`.
18
- */
19
- export declare function jsonValueToSqlite(value: bigint | boolean | null | number | string | undefined): SqliteValue;
20
- export declare function isJsonValue(value: SqliteValue): value is SqliteJsonValue;
21
- /**
22
- * Map database row to SqliteRow for use in sync rules.
23
- */
24
- export declare function toSyncRulesRow(row: DatabaseInputRow): SqliteRow;
25
- /**
26
- * Convert parameter query input to a SqliteJsonRow.
27
- *
28
- * @param parameters Generic JSON input
29
- */
30
- export declare function toSyncRulesParameters(parameters: Record<string, any>): SqliteJsonRow;
31
- /**
32
- * Convert to a SQLITE-equivalent value: NULL, TEXT, INTEGER, REAL or BLOB.
33
- *
34
- * Any object or array is converted to JSON TEXT.
35
- */
36
- export declare function toSyncRulesValue(data: any, autoBigNum?: boolean, keepUndefined?: boolean): SqliteValue;
37
- export declare function normalizeTokenParameters(token_parameters: Record<string, any>, user_parameters?: Record<string, any>): SyncParameters;
38
- /**
39
- * Only use this for serializing bucket names. Bucket names should never be parsed except perhaps for debug purposes.
40
- *
41
- * Important: REAL and INTEGER values matching the same number needs the same representation in the bucket name.
42
- */
43
- export declare const JSONBucketNameSerialize: {
44
- stringify(value: any, replacer?: Replacer, space?: number | string): string;
45
- };
@@ -1,163 +0,0 @@
1
- import { JSONBig, JsonContainer, stringifyRaw } from '../json/index.js';
2
- import { SQLITE_FALSE, SQLITE_TRUE } from './sql_support.js';
3
- export function isSelectStatement(q) {
4
- return q.type === 'select';
5
- }
6
- export function getBucketId(descriptor_id, bucket_parameters, params) {
7
- // Important: REAL and INTEGER values matching the same number needs the same representation in the bucket name.
8
- const paramArray = bucket_parameters.map((name) => params[`bucket.${name}`]);
9
- return `${descriptor_id}${JSONBucketNameSerialize.stringify(paramArray)}`;
10
- }
11
- const DEPTH_LIMIT = 10;
12
- /**
13
- * SqliteRow -> SqliteJsonRow.
14
- *
15
- * Use wherever data should be persisted.
16
- *
17
- * Basically just removes Uint8Array.
18
- */
19
- export function filterJsonRow(data) {
20
- const record = {};
21
- for (const key of Object.keys(data)) {
22
- const value = data[key];
23
- if (isJsonValue(value)) {
24
- record[key] = value;
25
- }
26
- }
27
- return record;
28
- }
29
- /**
30
- * Convert a parsed JSON scalar value to SqliteValue.
31
- *
32
- * Types specifically not supported in output are `boolean` and `undefined`.
33
- */
34
- export function jsonValueToSqlite(value) {
35
- if (typeof value === 'boolean') {
36
- return value ? SQLITE_TRUE : SQLITE_FALSE;
37
- }
38
- return value ?? null;
39
- }
40
- export function isJsonValue(value) {
41
- return value == null || typeof value === 'string' || typeof value === 'number' || typeof value === 'bigint';
42
- }
43
- function filterJsonData(data, depth = 0) {
44
- if (depth > DEPTH_LIMIT) {
45
- // This is primarily to prevent infinite recursion
46
- throw new Error(`json nested object depth exceeds the limit of ${DEPTH_LIMIT}`);
47
- }
48
- if (data == null) {
49
- return data; // null or undefined
50
- }
51
- if (typeof data === 'string' || typeof data === 'number') {
52
- return data;
53
- }
54
- if (typeof data === 'boolean') {
55
- return data ? SQLITE_TRUE : SQLITE_FALSE;
56
- }
57
- if (typeof data === 'bigint') {
58
- return data;
59
- }
60
- if (Array.isArray(data)) {
61
- return data.map((element) => filterJsonData(element, depth + 1));
62
- }
63
- if (ArrayBuffer.isView(data)) {
64
- return undefined;
65
- }
66
- if (data instanceof JsonContainer) {
67
- // Can be stringified directly when using our JSONBig implementation
68
- return data;
69
- }
70
- if (typeof data === 'object') {
71
- const record = {};
72
- for (const key of Object.keys(data)) {
73
- record[key] = filterJsonData(data[key], depth + 1);
74
- }
75
- return record;
76
- }
77
- return undefined;
78
- }
79
- /**
80
- * Map database row to SqliteRow for use in sync rules.
81
- */
82
- export function toSyncRulesRow(row) {
83
- const record = {};
84
- for (const key of Object.keys(row)) {
85
- record[key] = toSyncRulesValue(row[key], false, true);
86
- }
87
- return record;
88
- }
89
- /**
90
- * Convert parameter query input to a SqliteJsonRow.
91
- *
92
- * @param parameters Generic JSON input
93
- */
94
- export function toSyncRulesParameters(parameters) {
95
- const record = {};
96
- for (const key of Object.keys(parameters)) {
97
- record[key] = toSyncRulesValue(parameters[key], true, false);
98
- }
99
- return record;
100
- }
101
- /**
102
- * Convert to a SQLITE-equivalent value: NULL, TEXT, INTEGER, REAL or BLOB.
103
- *
104
- * Any object or array is converted to JSON TEXT.
105
- */
106
- export function toSyncRulesValue(data, autoBigNum, keepUndefined) {
107
- if (data == null) {
108
- // null or undefined
109
- if (keepUndefined) {
110
- return data;
111
- }
112
- return null;
113
- }
114
- if (typeof data === 'string') {
115
- return data;
116
- }
117
- if (typeof data === 'number') {
118
- if (Number.isInteger(data) && autoBigNum) {
119
- return BigInt(data);
120
- }
121
- return data;
122
- }
123
- if (typeof data === 'bigint') {
124
- return data;
125
- }
126
- if (typeof data === 'boolean') {
127
- return data ? SQLITE_TRUE : SQLITE_FALSE;
128
- }
129
- if (Array.isArray(data)) {
130
- // We may be able to avoid some parse + stringify cycles here for JsonSqliteContainer.
131
- return JSONBig.stringify(data.map((element) => filterJsonData(element)));
132
- }
133
- if (data instanceof Uint8Array) {
134
- return data;
135
- }
136
- if (data instanceof JsonContainer) {
137
- return data.toString();
138
- }
139
- if (typeof data === 'object') {
140
- const record = {};
141
- for (const key of Object.keys(data)) {
142
- record[key] = filterJsonData(data[key]);
143
- }
144
- return JSONBig.stringify(record);
145
- }
146
- return null;
147
- }
148
- export function normalizeTokenParameters(token_parameters, user_parameters) {
149
- return {
150
- token_parameters: toSyncRulesParameters(token_parameters),
151
- user_parameters: toSyncRulesParameters(user_parameters ?? {})
152
- };
153
- }
154
- /**
155
- * Only use this for serializing bucket names. Bucket names should never be parsed except perhaps for debug purposes.
156
- *
157
- * Important: REAL and INTEGER values matching the same number needs the same representation in the bucket name.
158
- */
159
- export const JSONBucketNameSerialize = {
160
- stringify(value, replacer, space) {
161
- return stringifyRaw(value, replacer, space);
162
- }
163
- };
@@ -1,26 +0,0 @@
1
- import 'dotenv/config';
2
- import { AccountsV5Client } from '../powersync-sdk/accounts/index.js';
3
- import { RequestHeaders } from '../powersync-sdk/fetch-clients/definitions.js';
4
- export declare const accountsClient: (headers: RequestHeaders) => AccountsV5Client<import("../powersync-sdk/fetch-clients/web-client.js").WebNetworkClient>;
5
- export declare const getOrgs: (bearerToken: string) => Promise<{
6
- total: number;
7
- count: number;
8
- cursor: string;
9
- more: boolean;
10
- } & {
11
- objects: ({
12
- label: string;
13
- locked?: boolean | undefined;
14
- business_customer_code?: string | undefined;
15
- business_customer_region?: import("../powersync-sdk/accounts/models.js").BUSINESS_REGION | undefined;
16
- pre_signup_trial_expiry?: string | undefined;
17
- trial?: boolean | undefined;
18
- trial_expiry?: string | undefined;
19
- } & {
20
- id: string;
21
- })[];
22
- }>;
23
- export declare const getPowerSyncApps: (bearerToken: string) => Promise<{
24
- name: string;
25
- value: string;
26
- }[]>;