effect-qb 0.17.0 → 4.0.0-beta.66

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 (38) hide show
  1. package/README.md +7 -0
  2. package/dist/mysql.js +207 -134
  3. package/dist/postgres/metadata.js +121 -52
  4. package/dist/postgres.js +210 -138
  5. package/dist/sqlite.js +207 -134
  6. package/package.json +2 -4
  7. package/src/internal/column-state.d.ts +3 -3
  8. package/src/internal/column-state.ts +3 -3
  9. package/src/internal/column.ts +8 -8
  10. package/src/internal/dialect.ts +1 -1
  11. package/src/internal/executor.ts +54 -35
  12. package/src/internal/query.d.ts +1 -1
  13. package/src/internal/query.ts +1 -1
  14. package/src/internal/runtime/driver-value-mapping.ts +3 -3
  15. package/src/internal/runtime/schema.ts +28 -38
  16. package/src/internal/runtime/value.ts +20 -23
  17. package/src/internal/scalar.d.ts +1 -1
  18. package/src/internal/scalar.ts +1 -1
  19. package/src/internal/schema-derivation.d.ts +12 -61
  20. package/src/internal/schema-derivation.ts +95 -43
  21. package/src/internal/table.d.ts +29 -22
  22. package/src/internal/table.ts +178 -29
  23. package/src/mysql/column.ts +6 -6
  24. package/src/mysql/executor.ts +4 -4
  25. package/src/mysql/function/temporal.ts +1 -1
  26. package/src/mysql/internal/dsl.ts +23 -17
  27. package/src/mysql/table.ts +28 -25
  28. package/src/postgres/column.ts +11 -11
  29. package/src/postgres/executor.ts +4 -4
  30. package/src/postgres/function/temporal.ts +1 -1
  31. package/src/postgres/internal/dsl.ts +23 -17
  32. package/src/postgres/schema-management.ts +1 -2
  33. package/src/postgres/table.ts +13 -21
  34. package/src/sqlite/column.ts +6 -6
  35. package/src/sqlite/executor.ts +4 -4
  36. package/src/sqlite/function/temporal.ts +1 -1
  37. package/src/sqlite/internal/dsl.ts +7 -6
  38. package/src/sqlite/table.ts +17 -25
package/dist/sqlite.js CHANGED
@@ -312,7 +312,7 @@ var references = (target) => foreignKey(target);
312
312
 
313
313
  // src/internal/runtime/value.ts
314
314
  import * as Schema3 from "effect/Schema";
315
- var brandString = (pattern2, brand5) => Schema3.String.pipe(Schema3.pattern(pattern2), Schema3.brand(brand5));
315
+ var brandString = (pattern, brand5) => Schema3.String.pipe(Schema3.check(Schema3.isPattern(pattern)), Schema3.brand(brand5));
316
316
  var localDatePattern = /^(\d{4})-(\d{2})-(\d{2})$/;
317
317
  var isValidLocalDateString = (value) => {
318
318
  const match = localDatePattern.exec(value);
@@ -365,11 +365,11 @@ var isValidInstantString = (value) => {
365
365
  const match = instantPattern.exec(value);
366
366
  return match !== null && isValidLocalDateString(match[1]) && isValidLocalTimeString(match[2]) && isValidOffset(match[3]);
367
367
  };
368
- var LocalDateStringSchema = Schema3.String.pipe(Schema3.pattern(localDatePattern), Schema3.filter(isValidLocalDateString), Schema3.brand("LocalDateString"));
369
- var LocalTimeStringSchema = Schema3.String.pipe(Schema3.pattern(localTimePattern), Schema3.filter(isValidLocalTimeString), Schema3.brand("LocalTimeString"));
370
- var OffsetTimeStringSchema = Schema3.String.pipe(Schema3.pattern(offsetTimePattern), Schema3.filter(isValidOffsetTimeString), Schema3.brand("OffsetTimeString"));
371
- var LocalDateTimeStringSchema = Schema3.String.pipe(Schema3.pattern(localDateTimePattern), Schema3.filter(isValidLocalDateTimeString), Schema3.brand("LocalDateTimeString"));
372
- var InstantStringSchema = Schema3.String.pipe(Schema3.pattern(instantPattern), Schema3.filter(isValidInstantString), Schema3.brand("InstantString"));
368
+ var LocalDateStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(localDatePattern)), Schema3.check(Schema3.makeFilter((value) => isValidLocalDateString(value))), Schema3.brand("LocalDateString"));
369
+ var LocalTimeStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(localTimePattern)), Schema3.check(Schema3.makeFilter((value) => isValidLocalTimeString(value))), Schema3.brand("LocalTimeString"));
370
+ var OffsetTimeStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(offsetTimePattern)), Schema3.check(Schema3.makeFilter((value) => isValidOffsetTimeString(value))), Schema3.brand("OffsetTimeString"));
371
+ var LocalDateTimeStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(localDateTimePattern)), Schema3.check(Schema3.makeFilter((value) => isValidLocalDateTimeString(value))), Schema3.brand("LocalDateTimeString"));
372
+ var InstantStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(instantPattern)), Schema3.check(Schema3.makeFilter((value) => isValidInstantString(value))), Schema3.brand("InstantString"));
373
373
  var YearStringSchema = brandString(/^\d{4}$/, "YearString");
374
374
  var canonicalizeBigIntString = (input) => {
375
375
  const trimmed = input.trim();
@@ -409,13 +409,22 @@ var isCanonicalDecimalString = (value) => {
409
409
  return false;
410
410
  }
411
411
  };
412
- var BigIntStringSchema = Schema3.String.pipe(Schema3.filter(isCanonicalBigIntString), Schema3.brand("BigIntString"));
413
- var DecimalStringSchema = Schema3.String.pipe(Schema3.filter(isCanonicalDecimalString), Schema3.brand("DecimalString"));
414
- var JsonValueSchema = Schema3.suspend(() => Schema3.Union(Schema3.String, Schema3.Number.pipe(Schema3.finite()), Schema3.Boolean, Schema3.Null, Schema3.Array(JsonValueSchema), Schema3.Record({
415
- key: Schema3.String,
416
- value: JsonValueSchema
417
- })));
418
- var JsonPrimitiveSchema = Schema3.Union(Schema3.String, Schema3.Number.pipe(Schema3.finite()), Schema3.Boolean, Schema3.Null);
412
+ var BigIntStringSchema = Schema3.String.pipe(Schema3.check(Schema3.makeFilter((value) => isCanonicalBigIntString(value))), Schema3.brand("BigIntString"));
413
+ var DecimalStringSchema = Schema3.String.pipe(Schema3.check(Schema3.makeFilter((value) => isCanonicalDecimalString(value))), Schema3.brand("DecimalString"));
414
+ var JsonValueSchema = Schema3.suspend(() => Schema3.Union([
415
+ Schema3.String,
416
+ Schema3.Number.check(Schema3.isFinite()),
417
+ Schema3.Boolean,
418
+ Schema3.Null,
419
+ Schema3.Array(JsonValueSchema),
420
+ Schema3.Record(Schema3.String, JsonValueSchema)
421
+ ]));
422
+ var JsonPrimitiveSchema = Schema3.Union([
423
+ Schema3.String,
424
+ Schema3.Number.check(Schema3.isFinite()),
425
+ Schema3.Boolean,
426
+ Schema3.Null
427
+ ]);
419
428
 
420
429
  // src/sqlite/datatypes/index.ts
421
430
  var exports_datatypes = {};
@@ -590,7 +599,7 @@ var custom = (schema2, dbType) => makeColumnDefinition(schema2, {
590
599
  ddlType: undefined,
591
600
  identity: undefined
592
601
  });
593
- var uuid = () => primitive(Schema4.UUID, sqliteDatatypes.uuid());
602
+ var uuid = () => primitive(Schema4.String.check(Schema4.isUUID()), sqliteDatatypes.uuid());
594
603
  var text = () => primitive(Schema4.String, sqliteDatatypes.text());
595
604
  var int = () => primitive(Schema4.Int, sqliteDatatypes.int());
596
605
  var number = (options) => makeColumnDefinition(DecimalStringSchema, {
@@ -1087,12 +1096,7 @@ var validateOptions = (tableName, fields2, options) => {
1087
1096
  };
1088
1097
 
1089
1098
  // src/internal/schema-derivation.ts
1090
- import * as VariantSchema from "@effect/experimental/VariantSchema";
1091
1099
  import * as Schema5 from "effect/Schema";
1092
- var TableSchema = VariantSchema.make({
1093
- variants: ["select", "insert", "update"],
1094
- defaultVariant: "select"
1095
- });
1096
1100
  var maybeBrandSchema = (column, tableName, columnName) => column.metadata.brand === true ? Schema5.brand(`${tableName}.${columnName}`)(column.schema) : column.schema;
1097
1101
  var selectSchema = (column, tableName, columnName) => column.metadata.nullable ? Schema5.NullOr(maybeBrandSchema(column, tableName, columnName)) : maybeBrandSchema(column, tableName, columnName);
1098
1102
  var insertSchema = (column, tableName, columnName) => {
@@ -1109,42 +1113,37 @@ var updateSchema = (column, tableName, columnName, isPrimaryKey) => {
1109
1113
  const base = column.metadata.nullable ? Schema5.NullOr(maybeBrandSchema(column, tableName, columnName)) : maybeBrandSchema(column, tableName, columnName);
1110
1114
  return Schema5.optional(base);
1111
1115
  };
1112
- var deriveSchemas = (tableName, fields2, primaryKeyColumns) => {
1116
+ var fieldSchemaForVariant = (variant, column, tableName, columnName, primaryKeySet) => {
1117
+ switch (variant) {
1118
+ case "select":
1119
+ return selectSchema(column, tableName, columnName);
1120
+ case "insert":
1121
+ return insertSchema(column, tableName, columnName);
1122
+ case "update":
1123
+ return updateSchema(column, tableName, columnName, primaryKeySet.has(columnName));
1124
+ }
1125
+ };
1126
+ var deriveSchema = (variant, tableName, fields2, primaryKeyColumns) => {
1113
1127
  const primaryKeySet = new Set(primaryKeyColumns);
1114
- const variants = {};
1128
+ const structFields = {};
1115
1129
  for (const [key, column] of Object.entries(fields2)) {
1116
- const config = {
1117
- select: selectSchema(column, tableName, key),
1118
- insert: undefined,
1119
- update: undefined
1120
- };
1121
- const insert = insertSchema(column, tableName, key);
1122
- const update = updateSchema(column, tableName, key, primaryKeySet.has(key));
1123
- if (insert !== undefined) {
1124
- config.insert = insert;
1125
- } else {
1126
- delete config.insert;
1127
- }
1128
- if (update !== undefined) {
1129
- config.update = update;
1130
- } else {
1131
- delete config.update;
1130
+ const schema3 = fieldSchemaForVariant(variant, column, tableName, key, primaryKeySet);
1131
+ if (schema3 !== undefined) {
1132
+ structFields[key] = schema3;
1132
1133
  }
1133
- variants[key] = TableSchema.Field(config);
1134
1134
  }
1135
- const struct = TableSchema.Struct(variants);
1136
- return {
1137
- select: TableSchema.extract(struct, "select"),
1138
- insert: TableSchema.extract(struct, "insert"),
1139
- update: TableSchema.extract(struct, "update")
1140
- };
1135
+ return Schema5.Struct(structFields);
1141
1136
  };
1137
+ var deriveSelectSchema = (tableName, fields2, primaryKeyColumns) => deriveSchema("select", tableName, fields2, primaryKeyColumns);
1138
+ var deriveInsertSchema = (tableName, fields2, primaryKeyColumns) => deriveSchema("insert", tableName, fields2, primaryKeyColumns);
1139
+ var deriveUpdateSchema = (tableName, fields2, primaryKeyColumns) => deriveSchema("update", tableName, fields2, primaryKeyColumns);
1142
1140
 
1143
1141
  // src/internal/table.ts
1144
1142
  var TypeId4 = Symbol.for("effect-qb/Table");
1145
1143
  var OptionsSymbol = Symbol.for("effect-qb/Table/normalizedOptions");
1146
1144
  var options = Symbol.for("effect-qb/Table/declaredOptions");
1147
1145
  var CacheSymbol = Symbol.for("effect-qb/Table/cache");
1146
+ var SchemaCacheSymbol = Symbol.for("effect-qb/Table/schemaCache");
1148
1147
  var DeclaredOptionsSymbol = Symbol.for("effect-qb/Table/factoryDeclaredOptions");
1149
1148
  var TableProto = {
1150
1149
  pipe() {
@@ -1167,14 +1166,86 @@ var buildArtifacts = (name, fields2, declaredOptions, schemaName) => {
1167
1166
  validateOptions(name, fields2, declaredOptions);
1168
1167
  const primaryKey3 = resolvePrimaryKeyColumns(fields2, declaredOptions);
1169
1168
  const columns = Object.fromEntries(Object.entries(fields2).map(([key, column]) => [key, bindColumn(name, key, column, name, schemaName)]));
1170
- const schemas = deriveSchemas(name, fields2, primaryKey3);
1171
1169
  return {
1172
1170
  columns,
1173
- schemas,
1174
1171
  normalizedOptions,
1175
1172
  primaryKey: primaryKey3
1176
1173
  };
1177
1174
  };
1175
+ var getSchemaCache = (table) => {
1176
+ const target = table;
1177
+ if (target[SchemaCacheSymbol] !== undefined) {
1178
+ return target[SchemaCacheSymbol];
1179
+ }
1180
+ const cache = {};
1181
+ Object.defineProperty(table, SchemaCacheSymbol, {
1182
+ configurable: true,
1183
+ value: cache
1184
+ });
1185
+ return cache;
1186
+ };
1187
+ var deriveTableSchema = (table, variant) => {
1188
+ const state = table[TypeId4];
1189
+ switch (variant) {
1190
+ case "select":
1191
+ return deriveSelectSchema(state.name, state.fields, state.primaryKey);
1192
+ case "insert":
1193
+ return deriveInsertSchema(state.name, state.fields, state.primaryKey);
1194
+ case "update":
1195
+ return deriveUpdateSchema(state.name, state.fields, state.primaryKey);
1196
+ }
1197
+ };
1198
+ var schemaFor = (table, variant) => {
1199
+ const cache = getSchemaCache(table);
1200
+ const cached = cache[variant];
1201
+ if (cached !== undefined) {
1202
+ return cached;
1203
+ }
1204
+ const schema3 = deriveTableSchema(table, variant);
1205
+ cache[variant] = schema3;
1206
+ return schema3;
1207
+ };
1208
+ function selectSchema2(table) {
1209
+ return schemaFor(table, "select");
1210
+ }
1211
+ function insertSchema2(table) {
1212
+ return schemaFor(table, "insert");
1213
+ }
1214
+ function updateSchema2(table) {
1215
+ return schemaFor(table, "update");
1216
+ }
1217
+ var schemasFor = (table) => {
1218
+ const cache = getSchemaCache(table);
1219
+ if (cache.schemas !== undefined) {
1220
+ return cache.schemas;
1221
+ }
1222
+ const schemas = {};
1223
+ Object.defineProperties(schemas, {
1224
+ select: {
1225
+ enumerable: true,
1226
+ get: () => selectSchema2(table)
1227
+ },
1228
+ insert: {
1229
+ enumerable: true,
1230
+ get: () => insertSchema2(table)
1231
+ },
1232
+ update: {
1233
+ enumerable: true,
1234
+ get: () => updateSchema2(table)
1235
+ }
1236
+ });
1237
+ cache.schemas = schemas;
1238
+ return schemas;
1239
+ };
1240
+ var defineSchemasGetter = (table) => {
1241
+ Object.defineProperty(table, "schemas", {
1242
+ configurable: true,
1243
+ enumerable: true,
1244
+ get() {
1245
+ return schemasFor(table);
1246
+ }
1247
+ });
1248
+ };
1178
1249
  var makeTable = (name, fields2, declaredOptions, baseName = name, kind = "schema", schemaName, schemaMode = "default") => {
1179
1250
  const resolvedSchemaName = schemaMode === "explicit" ? schemaName : "public";
1180
1251
  const artifacts = buildArtifacts(name, fields2, declaredOptions, resolvedSchemaName);
@@ -1182,7 +1253,7 @@ var makeTable = (name, fields2, declaredOptions, baseName = name, kind = "schema
1182
1253
  const table = attachPipe2(Object.create(TableProto));
1183
1254
  table.name = name;
1184
1255
  table.columns = artifacts.columns;
1185
- table.schemas = artifacts.schemas;
1256
+ defineSchemasGetter(table);
1186
1257
  table[TypeId4] = {
1187
1258
  name,
1188
1259
  baseName,
@@ -1255,7 +1326,6 @@ var ensureClassArtifacts = (self) => {
1255
1326
  const table = applyDeclaredOptions(makeTable(state.name, state.fields, [], state.name, "schema", state.schemaName, state.schemaName === undefined || state.schemaName === "public" ? "default" : "explicit"), classOptions);
1256
1327
  const artifacts = {
1257
1328
  columns: table.columns,
1258
- schemas: table.schemas,
1259
1329
  normalizedOptions: table[OptionsSymbol],
1260
1330
  primaryKey: table[TypeId4].primaryKey
1261
1331
  };
@@ -1278,7 +1348,7 @@ var makeOption = (option) => {
1278
1348
  return builder;
1279
1349
  };
1280
1350
  var option = (spec) => makeOption(spec);
1281
- function make2(name, fields2, schemaName) {
1351
+ function make(name, fields2, schemaName) {
1282
1352
  const resolvedSchemaName = arguments.length >= 3 ? schemaName : "public";
1283
1353
  return makeTable(name, fields2, [], name, "schema", resolvedSchemaName, arguments.length >= 3 ? "explicit" : "default");
1284
1354
  }
@@ -1295,7 +1365,7 @@ var alias = (table, aliasName) => {
1295
1365
  const aliased = attachPipe2(Object.create(TableProto));
1296
1366
  aliased.name = aliasName;
1297
1367
  aliased.columns = columns;
1298
- aliased.schemas = deriveSchemas(aliasName, state.fields, state.primaryKey);
1368
+ defineSchemasGetter(aliased);
1299
1369
  aliased[TypeId4] = {
1300
1370
  name: aliasName,
1301
1371
  baseName: state.baseName,
@@ -1336,7 +1406,7 @@ function Class(name, schemaName) {
1336
1406
  return ensureClassArtifacts(this).columns;
1337
1407
  }
1338
1408
  static get schemas() {
1339
- return ensureClassArtifacts(this).schemas;
1409
+ return schemasFor(this);
1340
1410
  }
1341
1411
  static get [TypeId4]() {
1342
1412
  const declaredOptions = extractDeclaredOptions(this[options]);
@@ -1406,7 +1476,7 @@ var foreignKey2 = (columns, target, referencedColumns) => makeOption({
1406
1476
  knownColumns: Object.keys(target()[TypeId4].fields)
1407
1477
  })
1408
1478
  });
1409
- var check = (name, predicate) => makeOption({
1479
+ var check2 = (name, predicate) => makeOption({
1410
1480
  kind: "check",
1411
1481
  name,
1412
1482
  predicate
@@ -5918,20 +5988,21 @@ var exports_executor = {};
5918
5988
  __export(exports_executor, {
5919
5989
  withTransaction: () => withTransaction2,
5920
5990
  withSavepoint: () => withSavepoint2,
5921
- make: () => make6,
5991
+ make: () => make5,
5922
5992
  driver: () => driver2,
5923
5993
  custom: () => custom3
5924
5994
  });
5925
5995
  import * as Effect2 from "effect/Effect";
5926
- import * as SqlClient3 from "@effect/sql/SqlClient";
5996
+ import * as SqlClient3 from "effect/unstable/sql/SqlClient";
5927
5997
  import * as Stream2 from "effect/Stream";
5928
5998
 
5929
5999
  // src/internal/executor.ts
5930
6000
  import * as Chunk from "effect/Chunk";
5931
6001
  import * as Effect from "effect/Effect";
6002
+ import * as Exit from "effect/Exit";
5932
6003
  import * as Option from "effect/Option";
5933
6004
  import * as Schema9 from "effect/Schema";
5934
- import * as SqlClient from "@effect/sql/SqlClient";
6005
+ import * as SqlClient from "effect/unstable/sql/SqlClient";
5935
6006
  import * as Stream from "effect/Stream";
5936
6007
 
5937
6008
  // src/internal/runtime/driver-value-mapping.ts
@@ -6108,7 +6179,7 @@ var renderJsonSelectSql = (sql, context) => {
6108
6179
  import * as Schema8 from "effect/Schema";
6109
6180
  import * as SchemaAST from "effect/SchemaAST";
6110
6181
  var schemaCache = new WeakMap;
6111
- var FiniteNumberSchema = Schema8.Number.pipe(Schema8.finite());
6182
+ var FiniteNumberSchema = Schema8.Number.check(Schema8.isFinite());
6112
6183
  var runtimeSchemaForTag = (tag) => {
6113
6184
  switch (tag) {
6114
6185
  case "string":
@@ -6136,14 +6207,11 @@ var runtimeSchemaForTag = (tag) => {
6136
6207
  case "decimalString":
6137
6208
  return DecimalStringSchema;
6138
6209
  case "bytes":
6139
- return Schema8.Uint8ArrayFromSelf;
6210
+ return Schema8.Uint8Array;
6140
6211
  case "array":
6141
6212
  return Schema8.Array(Schema8.Unknown);
6142
6213
  case "record":
6143
- return Schema8.Record({
6144
- key: Schema8.String,
6145
- value: Schema8.Unknown
6146
- });
6214
+ return Schema8.Record(Schema8.String, Schema8.Unknown);
6147
6215
  case "null":
6148
6216
  return Schema8.Null;
6149
6217
  case "unknown":
@@ -6181,22 +6249,18 @@ var unionAst = (asts) => {
6181
6249
  if (asts.length === 1) {
6182
6250
  return asts[0];
6183
6251
  }
6184
- return SchemaAST.Union.make(asts);
6252
+ return new SchemaAST.Union(asts, "anyOf");
6185
6253
  };
6186
6254
  var propertyAstOf = (ast, key2) => {
6187
6255
  switch (ast._tag) {
6188
- case "Transformation":
6189
- return propertyAstOf(SchemaAST.typeAST(ast), key2);
6190
- case "Refinement":
6191
- return propertyAstOf(ast.from, key2);
6192
6256
  case "Suspend":
6193
- return propertyAstOf(ast.f(), key2);
6194
- case "TypeLiteral": {
6257
+ return propertyAstOf(ast.thunk(), key2);
6258
+ case "Objects": {
6195
6259
  const property = ast.propertySignatures.find((entry) => entry.name === key2);
6196
6260
  if (property !== undefined) {
6197
6261
  return property.type;
6198
6262
  }
6199
- const index4 = ast.indexSignatures.find((entry) => entry.parameter._tag === "StringKeyword");
6263
+ const index4 = ast.indexSignatures.find((entry) => entry.parameter._tag === "String");
6200
6264
  return index4?.type;
6201
6265
  }
6202
6266
  case "Union": {
@@ -6212,21 +6276,17 @@ var propertyAstOf = (ast, key2) => {
6212
6276
  };
6213
6277
  var numberAstOf = (ast, index4) => {
6214
6278
  switch (ast._tag) {
6215
- case "Transformation":
6216
- return numberAstOf(SchemaAST.typeAST(ast), index4);
6217
- case "Refinement":
6218
- return numberAstOf(ast.from, index4);
6219
6279
  case "Suspend":
6220
- return numberAstOf(ast.f(), index4);
6221
- case "TupleType": {
6280
+ return numberAstOf(ast.thunk(), index4);
6281
+ case "Arrays": {
6222
6282
  const element = ast.elements[index4];
6223
6283
  if (element !== undefined) {
6224
- return element.type;
6284
+ return element;
6225
6285
  }
6226
6286
  if (ast.rest.length === 0) {
6227
6287
  return;
6228
6288
  }
6229
- return unionAst(ast.rest.map((entry) => entry.type));
6289
+ return unionAst(ast.rest);
6230
6290
  }
6231
6291
  case "Union": {
6232
6292
  const values2 = ast.types.flatMap((member) => {
@@ -6241,7 +6301,7 @@ var numberAstOf = (ast, index4) => {
6241
6301
  };
6242
6302
  var exactJsonSegments = (segments) => segments.every((segment) => segment.kind === "key" || segment.kind === "index");
6243
6303
  var schemaAstAtExactJsonPath = (schema4, segments) => {
6244
- let current = SchemaAST.typeAST(schema4.ast);
6304
+ let current = schema4.ast;
6245
6305
  for (const segment of segments) {
6246
6306
  if (segment.kind === "key") {
6247
6307
  const property = propertyAstOf(current, segment.key);
@@ -6271,28 +6331,28 @@ var unionSchemas = (schemas) => {
6271
6331
  if (resolved.length === 1) {
6272
6332
  return resolved[0];
6273
6333
  }
6274
- return Schema8.Union(...resolved);
6334
+ return Schema8.Union(resolved);
6275
6335
  };
6276
6336
  var firstSelectedExpression = (plan) => {
6277
6337
  const selection = getAst(plan).select;
6278
6338
  return flattenSelection(selection)[0]?.expression;
6279
6339
  };
6280
6340
  var isJsonCompatibleAst = (ast) => {
6341
+ ast = SchemaAST.toType(ast);
6281
6342
  switch (ast._tag) {
6282
- case "StringKeyword":
6283
- case "NumberKeyword":
6284
- case "BooleanKeyword":
6285
- case "TupleType":
6286
- case "TypeLiteral":
6343
+ case "String":
6344
+ case "Number":
6345
+ case "Boolean":
6346
+ case "Null":
6347
+ case "Arrays":
6348
+ case "Objects":
6287
6349
  return true;
6288
6350
  case "Literal":
6289
- return ast.literal === null || typeof ast.literal === "string" || typeof ast.literal === "number" || typeof ast.literal === "boolean";
6351
+ return typeof ast.literal === "string" || typeof ast.literal === "number" || typeof ast.literal === "boolean";
6290
6352
  case "Union":
6291
6353
  return ast.types.every(isJsonCompatibleAst);
6292
- case "Transformation":
6293
- return isJsonCompatibleAst(SchemaAST.typeAST(ast));
6294
6354
  case "Suspend":
6295
- return isJsonCompatibleAst(ast.f());
6355
+ return isJsonCompatibleAst(ast.thunk());
6296
6356
  default:
6297
6357
  return false;
6298
6358
  }
@@ -6301,14 +6361,14 @@ var jsonCompatibleSchema = (schema4) => {
6301
6361
  if (schema4 === undefined) {
6302
6362
  return;
6303
6363
  }
6304
- const ast = SchemaAST.typeAST(schema4.ast);
6364
+ const ast = SchemaAST.toType(schema4.ast);
6305
6365
  return isJsonCompatibleAst(ast) ? schema4 : JsonValueSchema;
6306
6366
  };
6307
6367
  var buildStructSchema = (entries, context) => {
6308
6368
  const fields2 = Object.fromEntries(entries.map((entry) => [entry.key, expressionRuntimeSchema(entry.value, context) ?? JsonValueSchema]));
6309
6369
  return Schema8.Struct(fields2);
6310
6370
  };
6311
- var buildTupleSchema = (values2, context) => Schema8.Tuple(...values2.map((value) => expressionRuntimeSchema(value, context) ?? JsonValueSchema));
6371
+ var buildTupleSchema = (values2, context) => Schema8.Tuple(values2.map((value) => expressionRuntimeSchema(value, context) ?? JsonValueSchema));
6312
6372
  var deriveCaseSchema = (ast, context) => {
6313
6373
  if (context === undefined) {
6314
6374
  return unionSchemas([
@@ -6505,24 +6565,31 @@ var hasWriteCapability = (plan) => {
6505
6565
  }
6506
6566
  return false;
6507
6567
  };
6508
- var makeRowDecodeError = (rendered, projection, expression, raw, stage, cause, normalized) => ({
6509
- _tag: "RowDecodeError",
6510
- message: stage === "normalize" ? `Failed to normalize projection '${projection.alias}'` : `Failed to decode projection '${projection.alias}' against its runtime schema`,
6511
- dialect: rendered.dialect,
6512
- query: {
6513
- sql: rendered.sql,
6514
- params: rendered.params
6515
- },
6516
- projection: {
6517
- alias: projection.alias,
6518
- path: projection.path
6519
- },
6520
- dbType: expression[TypeId].dbType,
6521
- raw,
6522
- normalized,
6523
- stage,
6524
- cause
6525
- });
6568
+ var makeRowDecodeError = (rendered, projection, expression, raw, stage, cause, normalized) => {
6569
+ const schemaError = Schema9.isSchemaError(cause) ? {
6570
+ message: cause.message,
6571
+ issue: cause.issue
6572
+ } : undefined;
6573
+ return {
6574
+ _tag: "RowDecodeError",
6575
+ message: stage === "normalize" ? `Failed to normalize projection '${projection.alias}'` : `Failed to decode projection '${projection.alias}' against its runtime schema`,
6576
+ dialect: rendered.dialect,
6577
+ query: {
6578
+ sql: rendered.sql,
6579
+ params: rendered.params
6580
+ },
6581
+ projection: {
6582
+ alias: projection.alias,
6583
+ path: projection.path
6584
+ },
6585
+ dbType: expression[TypeId].dbType,
6586
+ raw,
6587
+ normalized,
6588
+ stage,
6589
+ cause,
6590
+ ...schemaError === undefined ? {} : { schemaError }
6591
+ };
6592
+ };
6526
6593
  var hasOptionalSourceDependency = (expression, scope) => {
6527
6594
  const state = expression[TypeId];
6528
6595
  return Object.keys(state.dependencies).some((sourceName) => !scope.absentSourceNames.has(sourceName) && scope.sourceModes.get(sourceName) === "optional");
@@ -6565,8 +6632,8 @@ var decodeProjectionValue = (rendered, projection, expression, raw, scope, drive
6565
6632
  driverValueMapping: expression[TypeId].driverValueMapping,
6566
6633
  valueMappings
6567
6634
  });
6568
- } catch (cause) {
6569
- throw makeRowDecodeError(rendered, projection, expression, raw, "normalize", cause);
6635
+ } catch (cause2) {
6636
+ throw makeRowDecodeError(rendered, projection, expression, raw, "normalize", cause2);
6570
6637
  }
6571
6638
  }
6572
6639
  const nullability = effectiveRuntimeNullability(expression, scope);
@@ -6592,11 +6659,15 @@ var decodeProjectionValue = (rendered, projection, expression, raw, scope, drive
6592
6659
  if (Schema9.is(schema4)(normalized)) {
6593
6660
  return normalized;
6594
6661
  }
6595
- try {
6596
- return Schema9.decodeUnknownSync(schema4)(normalized);
6597
- } catch (cause) {
6598
- throw makeRowDecodeError(rendered, projection, expression, raw, "schema", cause, normalized);
6662
+ const decoded = Schema9.decodeUnknownExit(schema4)(normalized);
6663
+ if (Exit.isSuccess(decoded)) {
6664
+ return decoded.value;
6599
6665
  }
6666
+ const cause = Option.match(Exit.findErrorOption(decoded), {
6667
+ onNone: () => decoded.cause,
6668
+ onSome: (schemaError) => schemaError
6669
+ });
6670
+ throw makeRowDecodeError(rendered, projection, expression, raw, "schema", cause, normalized);
6600
6671
  };
6601
6672
  var makeRowDecoder = (rendered, plan, options2 = {}) => {
6602
6673
  const projections = flattenSelection(getAst(plan).select);
@@ -6619,15 +6690,11 @@ var makeRowDecoder = (rendered, plan, options2 = {}) => {
6619
6690
  return decoded;
6620
6691
  };
6621
6692
  };
6622
- var decodeChunk = (rendered, plan, rows, options2 = {}) => {
6623
- const decodeRow = makeRowDecoder(rendered, plan, options2);
6624
- return Chunk.unsafeFromArray(Chunk.toReadonlyArray(rows).map((row) => decodeRow(row)));
6625
- };
6626
6693
  var decodeRows = (rendered, plan, rows, options2 = {}) => {
6627
6694
  const decodeRow = makeRowDecoder(rendered, plan, options2);
6628
6695
  return rows.map((row) => decodeRow(row));
6629
6696
  };
6630
- var make4 = (dialect, execute) => ({
6697
+ var make3 = (dialect, execute) => ({
6631
6698
  dialect,
6632
6699
  execute(plan) {
6633
6700
  return execute(plan);
@@ -6650,7 +6717,7 @@ function driver(dialect, executeOrHandlers) {
6650
6717
  }
6651
6718
  };
6652
6719
  }
6653
- var streamFromSqlClient = (query) => Stream.unwrapScoped(Effect.flatMap(SqlClient.SqlClient, (sql) => Effect.flatMap(Effect.serviceOption(SqlClient.TransactionConnection), Option.match({
6720
+ var streamFromSqlClient = (query) => Stream.unwrap(Effect.flatMap(SqlClient.SqlClient, (sql) => Effect.flatMap(Effect.serviceOption(sql.transactionService), Option.match({
6654
6721
  onNone: () => sql.reserve,
6655
6722
  onSome: ([connection]) => Effect.succeed(connection)
6656
6723
  })).pipe(Effect.map((connection) => connection.executeStream(query.sql, [...query.params], undefined)))));
@@ -6676,7 +6743,7 @@ var validateProjectionPathsMatchSelection = (plan, projections) => {
6676
6743
  }
6677
6744
  }
6678
6745
  };
6679
- function make5(dialect, render) {
6746
+ function make4(dialect, render) {
6680
6747
  if (typeof render !== "function") {
6681
6748
  throw new Error(`Renderer.make requires an explicit render implementation for dialect: ${dialect}`);
6682
6749
  }
@@ -8184,8 +8251,8 @@ var fromDriver = (renderer, sqlDriver, driverMode = "raw", valueMappings) => ({
8184
8251
  },
8185
8252
  stream(plan) {
8186
8253
  const rendered = renderer.render(plan);
8187
- return Stream2.mapError(Stream2.mapChunksEffect(sqlDriver.stream(rendered), (rows) => Effect2.try({
8188
- try: () => decodeChunk(rendered, plan, rows, { driverMode, valueMappings }),
8254
+ return Stream2.mapError(Stream2.mapArrayEffect(sqlDriver.stream(rendered), (rows) => Effect2.try({
8255
+ try: () => decodeRows(rendered, plan, rows, { driverMode, valueMappings }),
8189
8256
  catch: (error) => error
8190
8257
  })), (error) => {
8191
8258
  if (typeof error === "object" && error !== null && "_tag" in error && error._tag === "RowDecodeError") {
@@ -8200,13 +8267,13 @@ var sqlClientDriver = () => driver2({
8200
8267
  execute: (query) => Effect2.flatMap(SqlClient3.SqlClient, (sql) => sql.unsafe(query.sql, [...query.params])),
8201
8268
  stream: (query) => Stream2.unwrap(Effect2.map(Effect2.flatMap(SqlClient3.SqlClient, (sql) => sql.unsafe(query.sql, [...query.params])), (rows) => Stream2.fromIterable(rows)))
8202
8269
  });
8203
- function make6(options2 = {}) {
8270
+ function make5(options2 = {}) {
8204
8271
  if (options2.driver) {
8205
- return fromDriver(options2.renderer ?? make5("sqlite", (plan) => renderSqlitePlan(plan, { valueMappings: options2.valueMappings })), options2.driver, options2.driverMode, options2.valueMappings);
8272
+ return fromDriver(options2.renderer ?? make4("sqlite", (plan) => renderSqlitePlan(plan, { valueMappings: options2.valueMappings })), options2.driver, options2.driverMode, options2.valueMappings);
8206
8273
  }
8207
- return fromDriver(options2.renderer ?? make5("sqlite", (plan) => renderSqlitePlan(plan, { valueMappings: options2.valueMappings })), sqlClientDriver(), options2.driverMode, options2.valueMappings);
8274
+ return fromDriver(options2.renderer ?? make4("sqlite", (plan) => renderSqlitePlan(plan, { valueMappings: options2.valueMappings })), sqlClientDriver(), options2.driverMode, options2.valueMappings);
8208
8275
  }
8209
- var custom3 = (execute) => make4("sqlite", execute);
8276
+ var custom3 = (execute) => make3("sqlite", execute);
8210
8277
  // src/sqlite/query.ts
8211
8278
  var exports_query2 = {};
8212
8279
  __export(exports_query2, {
@@ -8302,14 +8369,17 @@ var from2 = exportedFrom;
8302
8369
  // src/sqlite/table.ts
8303
8370
  var exports_table2 = {};
8304
8371
  __export(exports_table2, {
8372
+ updateSchema: () => updateSchema3,
8305
8373
  unique: () => unique4,
8374
+ selectSchema: () => selectSchema3,
8306
8375
  schema: () => schema4,
8307
8376
  primaryKey: () => primaryKey4,
8308
8377
  options: () => options2,
8309
- make: () => make7,
8378
+ make: () => make6,
8379
+ insertSchema: () => insertSchema3,
8310
8380
  index: () => index4,
8311
8381
  foreignKey: () => foreignKey3,
8312
- check: () => check2,
8382
+ check: () => check3,
8313
8383
  alias: () => alias2,
8314
8384
  TypeId: () => TypeId10,
8315
8385
  OptionsSymbol: () => OptionsSymbol2,
@@ -8318,7 +8388,7 @@ __export(exports_table2, {
8318
8388
  var TypeId10 = TypeId4;
8319
8389
  var OptionsSymbol2 = OptionsSymbol;
8320
8390
  var options2 = options;
8321
- var make7 = (name, fields2, schemaName = undefined) => make2(name, fields2, schemaName);
8391
+ var make6 = (name, fields2, schemaName = undefined) => make(name, fields2, schemaName);
8322
8392
  var schema4 = (schemaName) => {
8323
8393
  const table = (name, fields2, ...declaredOptions) => schema3(schemaName).table(name, fields2, ...declaredOptions);
8324
8394
  return {
@@ -8335,16 +8405,19 @@ var primaryKey4 = primaryKey3;
8335
8405
  var unique4 = unique3;
8336
8406
  var index4 = index2;
8337
8407
  var foreignKey3 = (columns, target, referencedColumns) => foreignKey2(columns, target, referencedColumns);
8338
- var check2 = check;
8408
+ var check3 = check2;
8409
+ var selectSchema3 = selectSchema2;
8410
+ var insertSchema3 = insertSchema2;
8411
+ var updateSchema3 = updateSchema2;
8339
8412
  // src/sqlite/renderer.ts
8340
8413
  var exports_renderer2 = {};
8341
8414
  __export(exports_renderer2, {
8342
8415
  sqlite: () => sqlite,
8343
- make: () => make8,
8416
+ make: () => make7,
8344
8417
  TypeId: () => TypeId8
8345
8418
  });
8346
- var make8 = (options3 = {}) => make5("sqlite", (plan) => renderSqlitePlan(plan, options3));
8347
- var sqlite = make8();
8419
+ var make7 = (options3 = {}) => make4("sqlite", (plan) => renderSqlitePlan(plan, options3));
8420
+ var sqlite = make7();
8348
8421
  export {
8349
8422
  exports_table2 as Table,
8350
8423
  exports_scalar as Scalar,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-qb",
3
- "version": "0.17.0",
3
+ "version": "4.0.0-beta.66",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -57,9 +57,7 @@
57
57
  "@typescript/native-preview": "beta"
58
58
  },
59
59
  "dependencies": {
60
- "@effect/experimental": "^0.57.0",
61
- "@effect/sql": "^0.48.0",
62
- "effect": "^3.19.3",
60
+ "effect": "4.0.0-beta.66",
63
61
  "pgsql-ast-parser": "^12.0.2"
64
62
  }
65
63
  }