@rocicorp/zero 0.18.2025032400 → 0.18.2025032800
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.
- package/out/advanced.js +0 -1
- package/out/{chunk-YAABAEJV.js → chunk-3S3SDA44.js} +205 -148
- package/out/chunk-3S3SDA44.js.map +7 -0
- package/out/{chunk-2B2QE5AT.js → chunk-MB3DEFRC.js} +25 -2
- package/out/{chunk-2B2QE5AT.js.map → chunk-MB3DEFRC.js.map} +2 -2
- package/out/{chunk-DSUPSGE4.js → chunk-NBZURO2P.js} +81 -26
- package/out/{chunk-DSUPSGE4.js.map → chunk-NBZURO2P.js.map} +4 -4
- package/out/{inspector-ROITQB3J.js → inspector-SH2ZK7O3.js} +253 -102
- package/out/inspector-SH2ZK7O3.js.map +7 -0
- package/out/react.js +2 -3
- package/out/react.js.map +2 -2
- package/out/shared/src/sentinels.d.ts +3 -0
- package/out/shared/src/sentinels.d.ts.map +1 -0
- package/out/solid.js +3 -4
- package/out/solid.js.map +2 -2
- package/out/z2s/src/compiler.d.ts +5 -3
- package/out/z2s/src/compiler.d.ts.map +1 -1
- package/out/z2s/src/compiler.js +116 -16
- package/out/z2s/src/compiler.js.map +1 -1
- package/out/z2s/src/sql.d.ts +8 -0
- package/out/z2s/src/sql.d.ts.map +1 -1
- package/out/z2s/src/sql.js +205 -11
- package/out/z2s/src/sql.js.map +1 -1
- package/out/zero/src/zero-cache-dev.d.ts +1 -1
- package/out/zero/src/zero-cache-dev.d.ts.map +1 -1
- package/out/zero/src/zero-cache-dev.js +1 -1
- package/out/zero/src/zero-cache-dev.js.map +1 -1
- package/out/zero-cache/src/auth/load-permissions.d.ts.map +1 -1
- package/out/zero-cache/src/auth/load-permissions.js +2 -1
- package/out/zero-cache/src/auth/load-permissions.js.map +1 -1
- package/out/zero-cache/src/config/zero-config.d.ts +1 -1
- package/out/zero-cache/src/config/zero-config.d.ts.map +1 -1
- package/out/zero-cache/src/config/zero-config.js +6 -3
- package/out/zero-cache/src/config/zero-config.js.map +1 -1
- package/out/zero-cache/src/db/migration-lite.d.ts.map +1 -1
- package/out/zero-cache/src/db/migration-lite.js +9 -9
- package/out/zero-cache/src/db/migration-lite.js.map +1 -1
- package/out/zero-cache/src/scripts/deploy-permissions.d.ts +1 -1
- package/out/zero-cache/src/scripts/deploy-permissions.d.ts.map +1 -1
- package/out/zero-cache/src/scripts/deploy-permissions.js +1 -1
- package/out/zero-cache/src/scripts/deploy-permissions.js.map +1 -1
- package/out/zero-cache/src/server/multi/config.d.ts +1 -1
- package/out/zero-cache/src/server/multi/main.d.ts +1 -1
- package/out/zero-cache/src/server/multi/main.d.ts.map +1 -1
- package/out/zero-cache/src/server/multi/main.js +1 -1
- package/out/zero-cache/src/server/multi/main.js.map +1 -1
- package/out/zero-cache/src/server/multi/run-worker.d.ts +1 -1
- package/out/zero-cache/src/server/multi/run-worker.d.ts.map +1 -1
- package/out/zero-cache/src/server/multi/run-worker.js +1 -1
- package/out/zero-cache/src/server/multi/run-worker.js.map +1 -1
- package/out/zero-cache/src/server/syncer.js +1 -1
- package/out/zero-cache/src/server/syncer.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/change-source.d.ts +1 -1
- package/out/zero-cache/src/services/change-source/pg/change-source.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/change-source.js +96 -42
- package/out/zero-cache/src/services/change-source/pg/change-source.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/decommission.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/decommission.js +16 -5
- package/out/zero-cache/src/services/change-source/pg/decommission.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts +1 -2
- package/out/zero-cache/src/services/change-source/pg/initial-sync.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/initial-sync.js +18 -31
- package/out/zero-cache/src/services/change-source/pg/initial-sync.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.d.ts +7 -35
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.js +42 -74
- package/out/zero-cache/src/services/change-source/pg/schema/ddl.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/init.d.ts +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/init.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/init.js +69 -21
- package/out/zero-cache/src/services/change-source/pg/schema/init.js.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts +54 -27
- package/out/zero-cache/src/services/change-source/pg/schema/shard.d.ts.map +1 -1
- package/out/zero-cache/src/services/change-source/pg/schema/shard.js +53 -16
- package/out/zero-cache/src/services/change-source/pg/schema/shard.js.map +1 -1
- package/out/zero-cache/src/services/mutagen/mutagen.d.ts +7 -5
- package/out/zero-cache/src/services/mutagen/mutagen.d.ts.map +1 -1
- package/out/zero-cache/src/services/mutagen/mutagen.js +20 -5
- package/out/zero-cache/src/services/mutagen/mutagen.js.map +1 -1
- package/out/zero-cache/src/services/mutagen/pusher.d.ts +1 -1
- package/out/zero-cache/src/services/mutagen/pusher.d.ts.map +1 -1
- package/out/zero-cache/src/services/mutagen/pusher.js +61 -9
- package/out/zero-cache/src/services/mutagen/pusher.js.map +1 -1
- package/out/zero-cache/src/services/replicator/change-processor.d.ts.map +1 -1
- package/out/zero-cache/src/services/replicator/change-processor.js +25 -14
- package/out/zero-cache/src/services/replicator/change-processor.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/client-handler.d.ts +8 -4
- package/out/zero-cache/src/services/view-syncer/client-handler.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/client-handler.js +47 -23
- package/out/zero-cache/src/services/view-syncer/client-handler.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/client-schema.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/client-schema.js +8 -2
- package/out/zero-cache/src/services/view-syncer/client-schema.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts +2 -0
- package/out/zero-cache/src/services/view-syncer/cvr-store.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/cvr-store.js +35 -0
- package/out/zero-cache/src/services/view-syncer/cvr-store.js.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts +3 -0
- package/out/zero-cache/src/services/view-syncer/view-syncer.d.ts.map +1 -1
- package/out/zero-cache/src/services/view-syncer/view-syncer.js +32 -20
- package/out/zero-cache/src/services/view-syncer/view-syncer.js.map +1 -1
- package/out/zero-cache/src/types/bigint-json.d.ts +1 -1
- package/out/zero-cache/src/types/bigint-json.d.ts.map +1 -1
- package/out/zero-cache/src/types/bigint-json.js.map +1 -1
- package/out/zero-cache/src/types/lite.d.ts.map +1 -1
- package/out/zero-cache/src/types/lite.js +4 -3
- package/out/zero-cache/src/types/lite.js.map +1 -1
- package/out/zero-cache/src/types/shards.d.ts +4 -0
- package/out/zero-cache/src/types/shards.d.ts.map +1 -1
- package/out/zero-cache/src/types/shards.js +1 -1
- package/out/zero-cache/src/types/shards.js.map +1 -1
- package/out/zero-cache/src/workers/connection.d.ts +1 -2
- package/out/zero-cache/src/workers/connection.d.ts.map +1 -1
- package/out/zero-cache/src/workers/connection.js +64 -21
- package/out/zero-cache/src/workers/connection.js.map +1 -1
- package/out/zero-cache/src/workers/replicator.d.ts.map +1 -1
- package/out/zero-cache/src/workers/replicator.js +4 -8
- package/out/zero-cache/src/workers/replicator.js.map +1 -1
- package/out/zero-cache/src/workers/syncer-ws-message-handler.d.ts.map +1 -1
- package/out/zero-cache/src/workers/syncer-ws-message-handler.js +16 -7
- package/out/zero-cache/src/workers/syncer-ws-message-handler.js.map +1 -1
- package/out/zero-client/src/client/custom.d.ts +9 -11
- package/out/zero-client/src/client/custom.d.ts.map +1 -1
- package/out/zero-client/src/client/inspector/inspector.d.ts +2 -1
- package/out/zero-client/src/client/inspector/inspector.d.ts.map +1 -1
- package/out/zero-client/src/client/inspector/types.d.ts +7 -2
- package/out/zero-client/src/client/inspector/types.d.ts.map +1 -1
- package/out/zero-client/src/client/mutation-tracker.d.ts +23 -8
- package/out/zero-client/src/client/mutation-tracker.d.ts.map +1 -1
- package/out/zero-client/src/client/options.d.ts +7 -2
- package/out/zero-client/src/client/options.d.ts.map +1 -1
- package/out/zero-client/src/client/query-manager.d.ts +2 -1
- package/out/zero-client/src/client/query-manager.d.ts.map +1 -1
- package/out/zero-client/src/client/zero.d.ts +1 -1
- package/out/zero-client/src/client/zero.d.ts.map +1 -1
- package/out/zero-client/src/mod.d.ts +7 -1
- package/out/zero-client/src/mod.d.ts.map +1 -1
- package/out/zero-pg/src/custom.d.ts +2 -13
- package/out/zero-pg/src/custom.d.ts.map +1 -1
- package/out/zero-pg/src/custom.js +11 -14
- package/out/zero-pg/src/custom.js.map +1 -1
- package/out/zero-pg/src/mod.d.ts +1 -2
- package/out/zero-pg/src/mod.d.ts.map +1 -1
- package/out/zero-pg/src/mod.js +1 -1
- package/out/zero-pg/src/mod.js.map +1 -1
- package/out/zero-pg/src/query.d.ts +2 -2
- package/out/zero-pg/src/query.d.ts.map +1 -1
- package/out/zero-pg/src/query.js +8 -15
- package/out/zero-pg/src/query.js.map +1 -1
- package/out/zero-pg/src/web.d.ts +3 -7
- package/out/zero-pg/src/web.d.ts.map +1 -1
- package/out/zero-pg/src/web.js +9 -15
- package/out/zero-pg/src/web.js.map +1 -1
- package/out/zero-protocol/src/client-schema.d.ts +1 -1
- package/out/zero-protocol/src/client-schema.d.ts.map +1 -1
- package/out/zero-protocol/src/client-schema.js +1 -1
- package/out/zero-protocol/src/client-schema.js.map +1 -1
- package/out/zero-protocol/src/down.d.ts +19 -6
- package/out/zero-protocol/src/down.d.ts.map +1 -1
- package/out/zero-protocol/src/down.js +2 -2
- package/out/zero-protocol/src/down.js.map +1 -1
- package/out/zero-protocol/src/inspect-down.d.ts +59 -0
- package/out/zero-protocol/src/inspect-down.d.ts.map +1 -0
- package/out/zero-protocol/src/inspect-down.js +23 -0
- package/out/zero-protocol/src/inspect-down.js.map +1 -0
- package/out/zero-protocol/src/inspect-up.d.ts +21 -0
- package/out/zero-protocol/src/inspect-up.d.ts.map +1 -0
- package/out/zero-protocol/src/inspect-up.js +12 -0
- package/out/zero-protocol/src/inspect-up.js.map +1 -0
- package/out/zero-protocol/src/mutation-type-enum.d.ts +1 -0
- package/out/zero-protocol/src/mutation-type-enum.d.ts.map +1 -1
- package/out/zero-protocol/src/protocol-version.d.ts +1 -1
- package/out/zero-protocol/src/protocol-version.d.ts.map +1 -1
- package/out/zero-protocol/src/protocol-version.js +3 -1
- package/out/zero-protocol/src/protocol-version.js.map +1 -1
- package/out/zero-protocol/src/push.d.ts +31 -18
- package/out/zero-protocol/src/push.d.ts.map +1 -1
- package/out/zero-protocol/src/push.js +7 -6
- package/out/zero-protocol/src/push.js.map +1 -1
- package/out/zero-protocol/src/up.d.ts +5 -1
- package/out/zero-protocol/src/up.d.ts.map +1 -1
- package/out/zero-protocol/src/up.js +2 -1
- package/out/zero-protocol/src/up.js.map +1 -1
- package/out/zero-react/src/use-query.d.ts +1 -2
- package/out/zero-react/src/use-query.d.ts.map +1 -1
- package/out/zero-schema/src/builder/table-builder.d.ts +13 -0
- package/out/zero-schema/src/builder/table-builder.d.ts.map +1 -1
- package/out/zero-schema/src/builder/table-builder.js +17 -0
- package/out/zero-schema/src/builder/table-builder.js.map +1 -1
- package/out/zero-schema/src/permissions.d.ts.map +1 -1
- package/out/zero-schema/src/table-schema.d.ts +3 -1
- package/out/zero-schema/src/table-schema.d.ts.map +1 -1
- package/out/zero-schema/src/table-schema.js.map +1 -1
- package/out/zero-solid/src/create-zero.d.ts.map +1 -1
- package/out/zero-solid/src/solid-view.d.ts +1 -2
- package/out/zero-solid/src/solid-view.d.ts.map +1 -1
- package/out/zero-solid/src/use-query.d.ts +1 -2
- package/out/zero-solid/src/use-query.d.ts.map +1 -1
- package/out/zero.js +7 -4
- package/out/zql/src/mutate/custom.d.ts +0 -1
- package/out/zql/src/mutate/custom.d.ts.map +1 -1
- package/out/zql/src/mutate/custom.js.map +1 -1
- package/out/zql/src/query/query-impl.d.ts +9 -6
- package/out/zql/src/query/query-impl.d.ts.map +1 -1
- package/out/zql/src/query/query-impl.js +16 -18
- package/out/zql/src/query/query-impl.js.map +1 -1
- package/out/zql/src/query/query-internal.d.ts +2 -9
- package/out/zql/src/query/query-internal.d.ts.map +1 -1
- package/out/zql/src/query/query.d.ts +5 -0
- package/out/zql/src/query/query.d.ts.map +1 -1
- package/out/zql/src/query/static-query.d.ts +1 -1
- package/out/zql/src/query/static-query.d.ts.map +1 -1
- package/out/zql/src/query/static-query.js +2 -2
- package/out/zql/src/query/static-query.js.map +1 -1
- package/out/zql/src/query/ttl.d.ts +1 -1
- package/out/zql/src/query/ttl.d.ts.map +1 -1
- package/out/zql/src/query/ttl.js +1 -1
- package/out/zql/src/query/ttl.js.map +1 -1
- package/out/zqlite/src/table-source.d.ts.map +1 -1
- package/out/zqlite/src/table-source.js +8 -0
- package/out/zqlite/src/table-source.js.map +1 -1
- package/package.json +4 -5
- package/out/chunk-ULOTOBTC.js +0 -1
- package/out/chunk-ULOTOBTC.js.map +0 -7
- package/out/chunk-YAABAEJV.js.map +0 -7
- package/out/inspector-ROITQB3J.js.map +0 -7
- package/out/zero-protocol/src/warm.d.ts +0 -10
- package/out/zero-protocol/src/warm.d.ts.map +0 -1
- package/out/zero-protocol/src/warm.js +0 -6
- package/out/zero-protocol/src/warm.js.map +0 -1
- package/out/zero-schema/src/mod.d.ts +0 -5
- package/out/zero-schema/src/mod.d.ts.map +0 -1
- package/out/zql/src/query/query-internal.js +0 -2
- package/out/zql/src/query/query-internal.js.map +0 -1
|
@@ -2,21 +2,22 @@ import {
|
|
|
2
2
|
ENTITIES_KEY_PREFIX,
|
|
3
3
|
Latest,
|
|
4
4
|
SUBQ_PREFIX,
|
|
5
|
-
astSchema,
|
|
6
5
|
clientToServer,
|
|
7
|
-
desiredQueriesPrefixForClient,
|
|
8
6
|
getClient,
|
|
9
7
|
getClientGroup,
|
|
10
|
-
getClientGroups,
|
|
11
8
|
getClients,
|
|
12
|
-
|
|
9
|
+
inspectQueriesDownSchema,
|
|
10
|
+
nanoid,
|
|
13
11
|
readFromHash,
|
|
14
|
-
|
|
12
|
+
readonly,
|
|
13
|
+
test,
|
|
15
14
|
valita_exports,
|
|
16
15
|
withRead,
|
|
17
16
|
zip
|
|
18
|
-
} from "./chunk-
|
|
19
|
-
import
|
|
17
|
+
} from "./chunk-NBZURO2P.js";
|
|
18
|
+
import {
|
|
19
|
+
normalizeTTL
|
|
20
|
+
} from "./chunk-MB3DEFRC.js";
|
|
20
21
|
import {
|
|
21
22
|
assert,
|
|
22
23
|
must,
|
|
@@ -185,21 +186,111 @@ function transformParameter(param) {
|
|
|
185
186
|
}
|
|
186
187
|
|
|
187
188
|
// ../z2s/src/sql.ts
|
|
188
|
-
import baseSql from "@databases/sql";
|
|
189
|
+
import baseSql, { SQLItemType } from "@databases/sql/web";
|
|
189
190
|
import {
|
|
190
191
|
escapePostgresIdentifier,
|
|
191
192
|
escapeSQLiteIdentifier
|
|
192
193
|
} from "@databases/escape-identifier";
|
|
193
|
-
var pgFormat = {
|
|
194
|
-
escapeIdentifier: (str) => escapePostgresIdentifier(str),
|
|
195
|
-
formatValue: (value, index) => ({ placeholder: `$${index + 1}`, value })
|
|
196
|
-
};
|
|
197
194
|
function formatPg(sql2) {
|
|
198
|
-
|
|
195
|
+
const format = new ReusingFormat(escapePostgresIdentifier);
|
|
196
|
+
return sql2.format((items) => formatFn(items, format));
|
|
197
|
+
}
|
|
198
|
+
var sqlConvert = Symbol("fromJson");
|
|
199
|
+
function sqlConvertArg(type, value, plural) {
|
|
200
|
+
return sql.value({ [sqlConvert]: true, type, value, plural });
|
|
201
|
+
}
|
|
202
|
+
function sqlConvertArgUnsafe(type, value, plural) {
|
|
203
|
+
return sqlConvertArg(type, value, plural);
|
|
199
204
|
}
|
|
205
|
+
var ReusingFormat = class {
|
|
206
|
+
#seen = /* @__PURE__ */ new Map();
|
|
207
|
+
escapeIdentifier;
|
|
208
|
+
constructor(escapeIdentifier) {
|
|
209
|
+
this.escapeIdentifier = escapeIdentifier;
|
|
210
|
+
}
|
|
211
|
+
formatValue = (value) => {
|
|
212
|
+
if (this.#seen.has(value)) {
|
|
213
|
+
return {
|
|
214
|
+
placeholder: `$${this.#seen.get(value)}`,
|
|
215
|
+
value: PREVIOUSLY_SEEN_VALUE
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
this.#seen.set(value, this.#seen.size + 1);
|
|
219
|
+
return { placeholder: `$${this.#seen.size}`, value };
|
|
220
|
+
};
|
|
221
|
+
};
|
|
200
222
|
var sql = baseSql.default;
|
|
223
|
+
var PREVIOUSLY_SEEN_VALUE = Symbol("PREVIOUSLY_SEEN_VALUE");
|
|
224
|
+
function formatFn(items, { escapeIdentifier, formatValue }) {
|
|
225
|
+
let text = "";
|
|
226
|
+
const values = [];
|
|
227
|
+
const localIdentifiers = /* @__PURE__ */ new Map();
|
|
228
|
+
for (const item of items) {
|
|
229
|
+
switch (item.type) {
|
|
230
|
+
// If this is just raw text, we add it directly to the query text.
|
|
231
|
+
case SQLItemType.RAW: {
|
|
232
|
+
text += item.text;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
// If we got a value SQL item, add a placeholder and add the value to our
|
|
236
|
+
// placeholder values array.
|
|
237
|
+
case SQLItemType.VALUE: {
|
|
238
|
+
const { placeholder, value } = formatValue(item.value, values.length);
|
|
239
|
+
text += placeholder;
|
|
240
|
+
if (value !== PREVIOUSLY_SEEN_VALUE) {
|
|
241
|
+
values.push(value);
|
|
242
|
+
}
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
// If we got an identifier type, escape the strings and get a local
|
|
246
|
+
// identifier for non-string identifiers.
|
|
247
|
+
case SQLItemType.IDENTIFIER: {
|
|
248
|
+
text += item.names.map((name) => {
|
|
249
|
+
if (typeof name === "string") return escapeIdentifier(name);
|
|
250
|
+
if (!localIdentifiers.has(name))
|
|
251
|
+
localIdentifiers.set(name, `__local_${localIdentifiers.size}__`);
|
|
252
|
+
return escapeIdentifier(localIdentifiers.get(name));
|
|
253
|
+
}).join(".");
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (text.trim()) {
|
|
259
|
+
const lines = text.split("\n");
|
|
260
|
+
const min = Math.min(
|
|
261
|
+
...lines.filter((l) => l.trim() !== "").map((l) => /^\s*/.exec(l)[0].length)
|
|
262
|
+
);
|
|
263
|
+
if (min) {
|
|
264
|
+
text = lines.map((line) => line.substr(min)).join("\n");
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
text: text.trim(),
|
|
269
|
+
values
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// ../zero-cache/src/types/bigint-json.ts
|
|
274
|
+
import {
|
|
275
|
+
parse as customParse,
|
|
276
|
+
stringify as customStringify
|
|
277
|
+
} from "json-custom-numbers";
|
|
278
|
+
var jsonValueSchema = valita_exports.lazy(() => {
|
|
279
|
+
const jsonObjectSchema2 = readonly(valita_exports.record(jsonValueSchema));
|
|
280
|
+
return valita_exports.union(
|
|
281
|
+
valita_exports.null(),
|
|
282
|
+
valita_exports.string(),
|
|
283
|
+
valita_exports.number(),
|
|
284
|
+
valita_exports.bigint(),
|
|
285
|
+
valita_exports.boolean(),
|
|
286
|
+
readonly(valita_exports.array(jsonValueSchema)),
|
|
287
|
+
jsonObjectSchema2
|
|
288
|
+
);
|
|
289
|
+
});
|
|
290
|
+
var jsonObjectSchema = readonly(valita_exports.record(jsonValueSchema));
|
|
201
291
|
|
|
202
292
|
// ../z2s/src/compiler.ts
|
|
293
|
+
var ZQL_RESULT_KEY = "zql_result";
|
|
203
294
|
function compile(ast, tables, format) {
|
|
204
295
|
const compiler = new Compiler(tables);
|
|
205
296
|
return compiler.compile(ast, format);
|
|
@@ -212,15 +303,20 @@ var Compiler = class {
|
|
|
212
303
|
this.#nameMapper = clientToServer(tables);
|
|
213
304
|
}
|
|
214
305
|
compile(ast, format) {
|
|
215
|
-
return this
|
|
306
|
+
return sql`SELECT ${this.#toJSON(
|
|
307
|
+
`root`,
|
|
308
|
+
format?.singular
|
|
309
|
+
)}::TEXT as ${sql.ident(ZQL_RESULT_KEY)} FROM (${this.select(
|
|
310
|
+
ast,
|
|
311
|
+
format,
|
|
312
|
+
void 0
|
|
313
|
+
)})${sql.ident(`root`)}`;
|
|
216
314
|
}
|
|
217
315
|
select(ast, format, correlation) {
|
|
218
316
|
const selectionSet = this.related(ast.related ?? [], format, ast.table);
|
|
219
|
-
const
|
|
220
|
-
for (const column of Object.
|
|
221
|
-
selectionSet.push(
|
|
222
|
-
sql`${sql.ident(ast.table)}.${this.#mapColumn(ast.table, column)}`
|
|
223
|
-
);
|
|
317
|
+
const tableSchema = this.#tables[ast.table];
|
|
318
|
+
for (const [column, columnSchema] of Object.entries(tableSchema.columns)) {
|
|
319
|
+
selectionSet.push(this.#selectCol(ast.table, column, columnSchema.type));
|
|
224
320
|
}
|
|
225
321
|
return sql`SELECT ${sql.join(selectionSet, ",")} FROM ${this.#mapTable(
|
|
226
322
|
ast.table
|
|
@@ -245,7 +341,7 @@ var Compiler = class {
|
|
|
245
341
|
if (!limit) {
|
|
246
342
|
return sql``;
|
|
247
343
|
}
|
|
248
|
-
return sql`LIMIT ${
|
|
344
|
+
return sql`LIMIT ${sqlConvertArg("number", limit)}`;
|
|
249
345
|
}
|
|
250
346
|
related(relationships, format, parentTable) {
|
|
251
347
|
return relationships.map(
|
|
@@ -261,7 +357,10 @@ var Compiler = class {
|
|
|
261
357
|
const [join, lastAlias, lastLimit, lastTable] = this.makeJunctionJoin(relationship);
|
|
262
358
|
const lastClientColumns = Object.keys(this.#tables[lastTable].columns);
|
|
263
359
|
return sql`(
|
|
264
|
-
SELECT ${
|
|
360
|
+
SELECT ${this.#toJSON(
|
|
361
|
+
`inner_${relationship.subquery.alias}`,
|
|
362
|
+
format?.singular
|
|
363
|
+
)} FROM (SELECT ${sql.join(
|
|
265
364
|
lastClientColumns.map(
|
|
266
365
|
(c) => sql`${sql.ident(lastAlias)}.${this.#mapColumn(lastTable, c)}`
|
|
267
366
|
),
|
|
@@ -283,7 +382,7 @@ var Compiler = class {
|
|
|
283
382
|
) as ${sql.ident(relationship.subquery.alias)}`;
|
|
284
383
|
}
|
|
285
384
|
return sql`(
|
|
286
|
-
SELECT ${format?.singular ? sql`` : sql`COALESCE(
|
|
385
|
+
SELECT ${format?.singular ? sql`` : sql`COALESCE(json_agg`}(row_to_json(${sql.ident(`inner_${relationship.subquery.alias}`)})) ${format?.singular ? sql`` : sql`, '[]'::json)`} FROM (${this.select(
|
|
287
386
|
relationship.subquery,
|
|
288
387
|
format,
|
|
289
388
|
this.correlate(
|
|
@@ -381,10 +480,14 @@ var Compiler = class {
|
|
|
381
480
|
case "NOT LIKE":
|
|
382
481
|
return sql`${this.valuePosition(
|
|
383
482
|
condition.left,
|
|
384
|
-
table
|
|
483
|
+
table,
|
|
484
|
+
this.#extractType(table, condition.left, condition.right),
|
|
485
|
+
false
|
|
385
486
|
)} ${sql.__dangerous__rawValue(condition.op)} ${this.valuePosition(
|
|
386
487
|
condition.right,
|
|
387
|
-
table
|
|
488
|
+
table,
|
|
489
|
+
this.#extractType(table, condition.right, condition.left),
|
|
490
|
+
false
|
|
388
491
|
)}`;
|
|
389
492
|
case "NOT IN":
|
|
390
493
|
case "IN":
|
|
@@ -395,17 +498,17 @@ var Compiler = class {
|
|
|
395
498
|
}
|
|
396
499
|
}
|
|
397
500
|
distinctFrom(condition, table) {
|
|
398
|
-
return sql`${this.valuePosition(condition.left, table)} ${condition.op === "IS" ? sql`IS NOT DISTINCT FROM` : sql`IS DISTINCT FROM`} ${this.valuePosition(condition.right, table)}`;
|
|
501
|
+
return sql`${this.valuePosition(condition.left, table, this.#extractType(table, condition.left, condition.right), false)} ${condition.op === "IS" ? sql`IS NOT DISTINCT FROM` : sql`IS DISTINCT FROM`} ${this.valuePosition(condition.right, table, this.#extractType(table, condition.right, condition.left), false)}`;
|
|
399
502
|
}
|
|
400
503
|
any(condition, table) {
|
|
401
|
-
return sql`${this.valuePosition(condition.left, table)} ${condition.op === "IN" ? sql`= ANY` : sql`!= ANY`} (${this.valuePosition(condition.right, table)})`;
|
|
504
|
+
return sql`${this.valuePosition(condition.left, table, this.#extractType(table, condition.left, condition.right), false)} ${condition.op === "IN" ? sql`= ANY` : sql`!= ANY`} (${this.valuePosition(condition.right, table, this.#extractType(table, condition.right, condition.left), true)})`;
|
|
402
505
|
}
|
|
403
|
-
valuePosition(value, table) {
|
|
506
|
+
valuePosition(value, table, valueType, plural) {
|
|
404
507
|
switch (value.type) {
|
|
405
508
|
case "column":
|
|
406
509
|
return this.#mapColumnNoAlias(table, value.name);
|
|
407
510
|
case "literal":
|
|
408
|
-
return
|
|
511
|
+
return sqlConvertArgUnsafe(valueType, value.value, plural);
|
|
409
512
|
case "static":
|
|
410
513
|
throw new Error(
|
|
411
514
|
"Static parameters must be bound to a value before compiling to SQL"
|
|
@@ -471,77 +574,125 @@ var Compiler = class {
|
|
|
471
574
|
const mapped = this.#nameMapper.tableName(table);
|
|
472
575
|
return sql.ident(mapped);
|
|
473
576
|
}
|
|
577
|
+
#selectCol(table, column, type) {
|
|
578
|
+
if (type === "date" || type === "timestamp") {
|
|
579
|
+
return sql`EXTRACT(EPOCH FROM ${sql.ident(
|
|
580
|
+
table
|
|
581
|
+
)}.${this.#mapColumnNoAlias(
|
|
582
|
+
table,
|
|
583
|
+
column
|
|
584
|
+
)}::timestamp AT TIME ZONE 'UTC') * 1000 as ${sql.ident(column)}`;
|
|
585
|
+
}
|
|
586
|
+
return sql`${sql.ident(table)}.${this.#mapColumn(table, column)}`;
|
|
587
|
+
}
|
|
588
|
+
#toJSON(table, singular = false) {
|
|
589
|
+
return sql`${singular ? sql`` : sql`COALESCE(json_agg`}(row_to_json(${sql.ident(table)})) ${singular ? sql`` : sql`, '[]'::json)`}`;
|
|
590
|
+
}
|
|
591
|
+
#extractType(table, first, second) {
|
|
592
|
+
const column = first.type === "column" ? first.name : second.type === "column" ? second.name : void 0;
|
|
593
|
+
if (column) {
|
|
594
|
+
return this.#tables[table].columns[column].type;
|
|
595
|
+
}
|
|
596
|
+
const literalValue = first.type === "literal" ? first.value : second.type === "literal" ? second.value : void 0;
|
|
597
|
+
assert(literalValue, "Literal value not found");
|
|
598
|
+
if (literalValue === null) {
|
|
599
|
+
return "null";
|
|
600
|
+
}
|
|
601
|
+
const jsType = typeof literalValue;
|
|
602
|
+
switch (jsType) {
|
|
603
|
+
case "boolean":
|
|
604
|
+
case "number":
|
|
605
|
+
case "string":
|
|
606
|
+
return jsType;
|
|
607
|
+
case "object":
|
|
608
|
+
case "bigint":
|
|
609
|
+
case "function":
|
|
610
|
+
case "symbol":
|
|
611
|
+
case "undefined":
|
|
612
|
+
throw new Error("Unsupported type: " + jsType);
|
|
613
|
+
default:
|
|
614
|
+
unreachable(jsType);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
474
617
|
};
|
|
475
618
|
|
|
476
619
|
// ../zero-client/src/client/inspector/inspector.ts
|
|
477
|
-
async function newInspector(rep, schema) {
|
|
620
|
+
async function newInspector(rep, schema, socket) {
|
|
478
621
|
const clientGroupID = await rep.clientGroupID;
|
|
479
|
-
return new Inspector(rep, schema, rep.clientID, clientGroupID);
|
|
622
|
+
return new Inspector(rep, schema, rep.clientID, clientGroupID, socket);
|
|
480
623
|
}
|
|
481
624
|
var Inspector = class {
|
|
482
625
|
#rep;
|
|
483
626
|
client;
|
|
484
627
|
clientGroup;
|
|
485
628
|
#schema;
|
|
486
|
-
|
|
629
|
+
socket;
|
|
630
|
+
constructor(rep, schema, clientID, clientGroupID, socket) {
|
|
487
631
|
this.#rep = rep;
|
|
488
632
|
this.#schema = schema;
|
|
489
|
-
this.client = new Client(rep, schema, clientID, clientGroupID);
|
|
633
|
+
this.client = new Client(rep, schema, socket, clientID, clientGroupID);
|
|
490
634
|
this.clientGroup = this.client.clientGroup;
|
|
635
|
+
this.socket = socket;
|
|
491
636
|
}
|
|
492
637
|
clients() {
|
|
493
638
|
return withDagRead(
|
|
494
639
|
this.#rep,
|
|
495
|
-
(dagRead) => clients(this.#rep, this.#schema, dagRead)
|
|
640
|
+
(dagRead) => clients(this.#rep, this.socket, this.#schema, dagRead)
|
|
496
641
|
);
|
|
497
642
|
}
|
|
498
643
|
clientsWithQueries() {
|
|
499
644
|
return withDagRead(
|
|
500
645
|
this.#rep,
|
|
501
|
-
(dagRead) => clientsWithQueries(this.#rep, this.#schema, dagRead)
|
|
646
|
+
(dagRead) => clientsWithQueries(this.#rep, this.socket, this.#schema, dagRead)
|
|
502
647
|
);
|
|
503
648
|
}
|
|
504
|
-
clientGroups() {
|
|
505
|
-
return withDagRead(this.#rep, async (dagRead) => {
|
|
506
|
-
const clientGroups = await getClientGroups(dagRead);
|
|
507
|
-
return [...clientGroups.keys()].map(
|
|
508
|
-
(clientGroupID) => new ClientGroup(this.#rep, this.#schema, clientGroupID)
|
|
509
|
-
);
|
|
510
|
-
});
|
|
511
|
-
}
|
|
512
649
|
};
|
|
650
|
+
function rpc(socket, arg, downSchema) {
|
|
651
|
+
assert(socket, "WebSocket not available");
|
|
652
|
+
return new Promise((resolve, reject) => {
|
|
653
|
+
const id = nanoid();
|
|
654
|
+
const f = (ev) => {
|
|
655
|
+
const msg = JSON.parse(ev.data);
|
|
656
|
+
if (msg[0] === "inspect") {
|
|
657
|
+
const body = msg[1];
|
|
658
|
+
if (body.id !== id) {
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
const res = test(body, downSchema);
|
|
662
|
+
if (res.ok) {
|
|
663
|
+
resolve(res.value.value);
|
|
664
|
+
} else {
|
|
665
|
+
reject(res.error);
|
|
666
|
+
}
|
|
667
|
+
socket.removeEventListener("message", f);
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
socket.addEventListener("message", f);
|
|
671
|
+
socket.send(
|
|
672
|
+
JSON.stringify(["inspect", { ...arg, id }])
|
|
673
|
+
);
|
|
674
|
+
});
|
|
675
|
+
}
|
|
513
676
|
var Client = class {
|
|
514
677
|
#rep;
|
|
515
678
|
id;
|
|
516
679
|
clientGroup;
|
|
517
680
|
#schema;
|
|
518
|
-
|
|
681
|
+
#socket;
|
|
682
|
+
constructor(rep, schema, socket, id, clientGroupID) {
|
|
519
683
|
this.#rep = rep;
|
|
520
684
|
this.#schema = schema;
|
|
685
|
+
this.#socket = socket;
|
|
521
686
|
this.id = id;
|
|
522
|
-
this.clientGroup = new ClientGroup(rep, schema, clientGroupID);
|
|
687
|
+
this.clientGroup = new ClientGroup(rep, socket, schema, clientGroupID);
|
|
523
688
|
}
|
|
524
|
-
queries() {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
break;
|
|
532
|
-
}
|
|
533
|
-
const hash = key.substring(prefix.length);
|
|
534
|
-
const got = await tree.has(toGotQueriesKey(hash));
|
|
535
|
-
const q = new Query(
|
|
536
|
-
hash,
|
|
537
|
-
parse(value, astSchema),
|
|
538
|
-
got,
|
|
539
|
-
this.#schema
|
|
540
|
-
);
|
|
541
|
-
qs.push(q);
|
|
542
|
-
}
|
|
543
|
-
return qs;
|
|
544
|
-
});
|
|
689
|
+
async queries() {
|
|
690
|
+
const rows = await rpc(
|
|
691
|
+
this.#socket(),
|
|
692
|
+
{ op: "queries", clientID: this.id },
|
|
693
|
+
inspectQueriesDownSchema
|
|
694
|
+
);
|
|
695
|
+
return rows.map((row) => new Query(row, this.#schema));
|
|
545
696
|
}
|
|
546
697
|
map() {
|
|
547
698
|
return withDagRead(this.#rep, async (dagRead) => {
|
|
@@ -572,8 +723,10 @@ var ClientGroup = class {
|
|
|
572
723
|
#rep;
|
|
573
724
|
id;
|
|
574
725
|
#schema;
|
|
575
|
-
|
|
726
|
+
#socket;
|
|
727
|
+
constructor(rep, socket, schema, id) {
|
|
576
728
|
this.#rep = rep;
|
|
729
|
+
this.#socket = socket;
|
|
577
730
|
this.#schema = schema;
|
|
578
731
|
this.id = id;
|
|
579
732
|
}
|
|
@@ -582,6 +735,7 @@ var ClientGroup = class {
|
|
|
582
735
|
this.#rep,
|
|
583
736
|
(dagRead) => clients(
|
|
584
737
|
this.#rep,
|
|
738
|
+
this.#socket,
|
|
585
739
|
this.#schema,
|
|
586
740
|
dagRead,
|
|
587
741
|
([_, v]) => v.clientGroupID === this.id
|
|
@@ -593,29 +747,20 @@ var ClientGroup = class {
|
|
|
593
747
|
this.#rep,
|
|
594
748
|
(dagRead) => clientsWithQueries(
|
|
595
749
|
this.#rep,
|
|
750
|
+
this.#socket,
|
|
596
751
|
this.#schema,
|
|
597
752
|
dagRead,
|
|
598
753
|
([_, v]) => v.clientGroupID === this.id
|
|
599
754
|
)
|
|
600
755
|
);
|
|
601
756
|
}
|
|
602
|
-
queries() {
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
);
|
|
610
|
-
const qs = /* @__PURE__ */ new Map();
|
|
611
|
-
await Promise.all(
|
|
612
|
-
cs.map(async (client) => {
|
|
613
|
-
const clientQueries = await client.queries();
|
|
614
|
-
clientQueries.forEach((q) => qs.set(q.id, q));
|
|
615
|
-
})
|
|
616
|
-
);
|
|
617
|
-
return [...qs.values()];
|
|
618
|
-
});
|
|
757
|
+
async queries() {
|
|
758
|
+
const rows = await rpc(
|
|
759
|
+
this.#socket(),
|
|
760
|
+
{ op: "queries" },
|
|
761
|
+
inspectQueriesDownSchema
|
|
762
|
+
);
|
|
763
|
+
return rows.map((row) => new Query(row, this.#schema));
|
|
619
764
|
}
|
|
620
765
|
};
|
|
621
766
|
async function withDagRead(rep, f) {
|
|
@@ -636,14 +781,14 @@ async function getBTree(dagRead, clientID) {
|
|
|
636
781
|
);
|
|
637
782
|
return dbRead.map;
|
|
638
783
|
}
|
|
639
|
-
async function clients(rep, schema, dagRead, predicate = () => true) {
|
|
784
|
+
async function clients(rep, socket, schema, dagRead, predicate = () => true) {
|
|
640
785
|
const clients2 = await getClients(dagRead);
|
|
641
786
|
return [...clients2.entries()].filter(predicate).map(
|
|
642
|
-
([clientID, { clientGroupID }]) => new Client(rep, schema, clientID, clientGroupID)
|
|
787
|
+
([clientID, { clientGroupID }]) => new Client(rep, schema, socket, clientID, clientGroupID)
|
|
643
788
|
);
|
|
644
789
|
}
|
|
645
|
-
async function clientsWithQueries(rep, schema, dagRead, predicate = () => true) {
|
|
646
|
-
const allClients = await clients(rep, schema, dagRead, predicate);
|
|
790
|
+
async function clientsWithQueries(rep, socket, schema, dagRead, predicate = () => true) {
|
|
791
|
+
const allClients = await clients(rep, socket, schema, dagRead, predicate);
|
|
647
792
|
const clientsWithQueries2 = [];
|
|
648
793
|
await Promise.all(
|
|
649
794
|
allClients.map(async (client) => {
|
|
@@ -656,29 +801,35 @@ async function clientsWithQueries(rep, schema, dagRead, predicate = () => true)
|
|
|
656
801
|
return clientsWithQueries2;
|
|
657
802
|
}
|
|
658
803
|
var Query = class {
|
|
659
|
-
id;
|
|
660
804
|
ast;
|
|
661
805
|
got;
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
806
|
+
ttl;
|
|
807
|
+
inactivatedAt;
|
|
808
|
+
rowCount;
|
|
809
|
+
deleted;
|
|
810
|
+
id;
|
|
811
|
+
sql;
|
|
812
|
+
zql;
|
|
813
|
+
clientID;
|
|
814
|
+
constructor(row, schema) {
|
|
815
|
+
this.clientID = row.clientID;
|
|
816
|
+
this.id = row.queryID;
|
|
817
|
+
this.inactivatedAt = row.inactivatedAt === null ? null : new Date(row.inactivatedAt);
|
|
818
|
+
this.ttl = normalizeTTL(row.ttl);
|
|
819
|
+
this.ast = row.ast;
|
|
820
|
+
this.got = row.got;
|
|
821
|
+
this.rowCount = row.rowCount;
|
|
822
|
+
this.deleted = row.deleted;
|
|
670
823
|
const format = {
|
|
671
824
|
singular: false,
|
|
672
825
|
relationships: {}
|
|
673
826
|
};
|
|
674
|
-
const sqlQuery = formatPg(compile(this.ast,
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
get zql() {
|
|
678
|
-
return this.ast.table + astToZQL(this.ast);
|
|
827
|
+
const sqlQuery = formatPg(compile(this.ast, schema.tables, format));
|
|
828
|
+
this.sql = sqlQuery.text;
|
|
829
|
+
this.zql = this.ast.table + astToZQL(this.ast);
|
|
679
830
|
}
|
|
680
831
|
};
|
|
681
832
|
export {
|
|
682
833
|
newInspector
|
|
683
834
|
};
|
|
684
|
-
//# sourceMappingURL=inspector-
|
|
835
|
+
//# sourceMappingURL=inspector-SH2ZK7O3.js.map
|