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/README.md CHANGED
@@ -8,10 +8,17 @@
8
8
  bun add effect-qb
9
9
  ```
10
10
 
11
+ For the parallel Effect v4 beta lane:
12
+
13
+ ```sh
14
+ bun add effect-qb@beta effect@4.0.0-beta.66
15
+ ```
16
+
11
17
  ## Entry points
12
18
 
13
19
  - `effect-qb/postgres`
14
20
  - `effect-qb/mysql`
21
+ - `effect-qb/sqlite`
15
22
  - `effect-qb/postgres/metadata`
16
23
 
17
24
  `effect-qb/postgres/metadata` exposes normalized table and enum metadata helpers used by `effectdb`.
package/dist/mysql.js CHANGED
@@ -311,7 +311,7 @@ var references = (target) => foreignKey(target);
311
311
 
312
312
  // src/internal/runtime/value.ts
313
313
  import * as Schema3 from "effect/Schema";
314
- var brandString = (pattern2, brand5) => Schema3.String.pipe(Schema3.pattern(pattern2), Schema3.brand(brand5));
314
+ var brandString = (pattern, brand5) => Schema3.String.pipe(Schema3.check(Schema3.isPattern(pattern)), Schema3.brand(brand5));
315
315
  var localDatePattern = /^(\d{4})-(\d{2})-(\d{2})$/;
316
316
  var isValidLocalDateString = (value) => {
317
317
  const match = localDatePattern.exec(value);
@@ -364,11 +364,11 @@ var isValidInstantString = (value) => {
364
364
  const match = instantPattern.exec(value);
365
365
  return match !== null && isValidLocalDateString(match[1]) && isValidLocalTimeString(match[2]) && isValidOffset(match[3]);
366
366
  };
367
- var LocalDateStringSchema = Schema3.String.pipe(Schema3.pattern(localDatePattern), Schema3.filter(isValidLocalDateString), Schema3.brand("LocalDateString"));
368
- var LocalTimeStringSchema = Schema3.String.pipe(Schema3.pattern(localTimePattern), Schema3.filter(isValidLocalTimeString), Schema3.brand("LocalTimeString"));
369
- var OffsetTimeStringSchema = Schema3.String.pipe(Schema3.pattern(offsetTimePattern), Schema3.filter(isValidOffsetTimeString), Schema3.brand("OffsetTimeString"));
370
- var LocalDateTimeStringSchema = Schema3.String.pipe(Schema3.pattern(localDateTimePattern), Schema3.filter(isValidLocalDateTimeString), Schema3.brand("LocalDateTimeString"));
371
- var InstantStringSchema = Schema3.String.pipe(Schema3.pattern(instantPattern), Schema3.filter(isValidInstantString), Schema3.brand("InstantString"));
367
+ var LocalDateStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(localDatePattern)), Schema3.check(Schema3.makeFilter((value) => isValidLocalDateString(value))), Schema3.brand("LocalDateString"));
368
+ var LocalTimeStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(localTimePattern)), Schema3.check(Schema3.makeFilter((value) => isValidLocalTimeString(value))), Schema3.brand("LocalTimeString"));
369
+ var OffsetTimeStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(offsetTimePattern)), Schema3.check(Schema3.makeFilter((value) => isValidOffsetTimeString(value))), Schema3.brand("OffsetTimeString"));
370
+ var LocalDateTimeStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(localDateTimePattern)), Schema3.check(Schema3.makeFilter((value) => isValidLocalDateTimeString(value))), Schema3.brand("LocalDateTimeString"));
371
+ var InstantStringSchema = Schema3.String.pipe(Schema3.check(Schema3.isPattern(instantPattern)), Schema3.check(Schema3.makeFilter((value) => isValidInstantString(value))), Schema3.brand("InstantString"));
372
372
  var YearStringSchema = brandString(/^\d{4}$/, "YearString");
373
373
  var canonicalizeBigIntString = (input) => {
374
374
  const trimmed = input.trim();
@@ -408,13 +408,22 @@ var isCanonicalDecimalString = (value) => {
408
408
  return false;
409
409
  }
410
410
  };
411
- var BigIntStringSchema = Schema3.String.pipe(Schema3.filter(isCanonicalBigIntString), Schema3.brand("BigIntString"));
412
- var DecimalStringSchema = Schema3.String.pipe(Schema3.filter(isCanonicalDecimalString), Schema3.brand("DecimalString"));
413
- var JsonValueSchema = Schema3.suspend(() => Schema3.Union(Schema3.String, Schema3.Number.pipe(Schema3.finite()), Schema3.Boolean, Schema3.Null, Schema3.Array(JsonValueSchema), Schema3.Record({
414
- key: Schema3.String,
415
- value: JsonValueSchema
416
- })));
417
- var JsonPrimitiveSchema = Schema3.Union(Schema3.String, Schema3.Number.pipe(Schema3.finite()), Schema3.Boolean, Schema3.Null);
411
+ var BigIntStringSchema = Schema3.String.pipe(Schema3.check(Schema3.makeFilter((value) => isCanonicalBigIntString(value))), Schema3.brand("BigIntString"));
412
+ var DecimalStringSchema = Schema3.String.pipe(Schema3.check(Schema3.makeFilter((value) => isCanonicalDecimalString(value))), Schema3.brand("DecimalString"));
413
+ var JsonValueSchema = Schema3.suspend(() => Schema3.Union([
414
+ Schema3.String,
415
+ Schema3.Number.check(Schema3.isFinite()),
416
+ Schema3.Boolean,
417
+ Schema3.Null,
418
+ Schema3.Array(JsonValueSchema),
419
+ Schema3.Record(Schema3.String, JsonValueSchema)
420
+ ]));
421
+ var JsonPrimitiveSchema = Schema3.Union([
422
+ Schema3.String,
423
+ Schema3.Number.check(Schema3.isFinite()),
424
+ Schema3.Boolean,
425
+ Schema3.Null
426
+ ]);
418
427
 
419
428
  // src/mysql/datatypes/index.ts
420
429
  var exports_datatypes = {};
@@ -671,7 +680,7 @@ var custom = (schema2, dbType) => makeColumnDefinition(schema2, {
671
680
  ddlType: undefined,
672
681
  identity: undefined
673
682
  });
674
- var uuid = () => primitive(Schema4.UUID, mysqlDatatypes.uuid());
683
+ var uuid = () => primitive(Schema4.String.check(Schema4.isUUID()), mysqlDatatypes.uuid());
675
684
  var text = () => primitive(Schema4.String, mysqlDatatypes.text());
676
685
  var int = () => primitive(Schema4.Int, mysqlDatatypes.int());
677
686
  var number = (options) => makeColumnDefinition(DecimalStringSchema, {
@@ -110062,12 +110071,7 @@ var validateOptions = (tableName, fields2, options) => {
110062
110071
  };
110063
110072
 
110064
110073
  // src/internal/schema-derivation.ts
110065
- import * as VariantSchema from "@effect/experimental/VariantSchema";
110066
110074
  import * as Schema5 from "effect/Schema";
110067
- var TableSchema = VariantSchema.make({
110068
- variants: ["select", "insert", "update"],
110069
- defaultVariant: "select"
110070
- });
110071
110075
  var maybeBrandSchema = (column, tableName, columnName) => column.metadata.brand === true ? Schema5.brand(`${tableName}.${columnName}`)(column.schema) : column.schema;
110072
110076
  var selectSchema = (column, tableName, columnName) => column.metadata.nullable ? Schema5.NullOr(maybeBrandSchema(column, tableName, columnName)) : maybeBrandSchema(column, tableName, columnName);
110073
110077
  var insertSchema = (column, tableName, columnName) => {
@@ -110084,42 +110088,37 @@ var updateSchema = (column, tableName, columnName, isPrimaryKey) => {
110084
110088
  const base = column.metadata.nullable ? Schema5.NullOr(maybeBrandSchema(column, tableName, columnName)) : maybeBrandSchema(column, tableName, columnName);
110085
110089
  return Schema5.optional(base);
110086
110090
  };
110087
- var deriveSchemas = (tableName, fields2, primaryKeyColumns) => {
110091
+ var fieldSchemaForVariant = (variant, column, tableName, columnName, primaryKeySet) => {
110092
+ switch (variant) {
110093
+ case "select":
110094
+ return selectSchema(column, tableName, columnName);
110095
+ case "insert":
110096
+ return insertSchema(column, tableName, columnName);
110097
+ case "update":
110098
+ return updateSchema(column, tableName, columnName, primaryKeySet.has(columnName));
110099
+ }
110100
+ };
110101
+ var deriveSchema = (variant, tableName, fields2, primaryKeyColumns) => {
110088
110102
  const primaryKeySet = new Set(primaryKeyColumns);
110089
- const variants = {};
110103
+ const structFields = {};
110090
110104
  for (const [key, column] of Object.entries(fields2)) {
110091
- const config = {
110092
- select: selectSchema(column, tableName, key),
110093
- insert: undefined,
110094
- update: undefined
110095
- };
110096
- const insert = insertSchema(column, tableName, key);
110097
- const update = updateSchema(column, tableName, key, primaryKeySet.has(key));
110098
- if (insert !== undefined) {
110099
- config.insert = insert;
110100
- } else {
110101
- delete config.insert;
110102
- }
110103
- if (update !== undefined) {
110104
- config.update = update;
110105
- } else {
110106
- delete config.update;
110105
+ const schema3 = fieldSchemaForVariant(variant, column, tableName, key, primaryKeySet);
110106
+ if (schema3 !== undefined) {
110107
+ structFields[key] = schema3;
110107
110108
  }
110108
- variants[key] = TableSchema.Field(config);
110109
110109
  }
110110
- const struct = TableSchema.Struct(variants);
110111
- return {
110112
- select: TableSchema.extract(struct, "select"),
110113
- insert: TableSchema.extract(struct, "insert"),
110114
- update: TableSchema.extract(struct, "update")
110115
- };
110110
+ return Schema5.Struct(structFields);
110116
110111
  };
110112
+ var deriveSelectSchema = (tableName, fields2, primaryKeyColumns) => deriveSchema("select", tableName, fields2, primaryKeyColumns);
110113
+ var deriveInsertSchema = (tableName, fields2, primaryKeyColumns) => deriveSchema("insert", tableName, fields2, primaryKeyColumns);
110114
+ var deriveUpdateSchema = (tableName, fields2, primaryKeyColumns) => deriveSchema("update", tableName, fields2, primaryKeyColumns);
110117
110115
 
110118
110116
  // src/internal/table.ts
110119
110117
  var TypeId4 = Symbol.for("effect-qb/Table");
110120
110118
  var OptionsSymbol = Symbol.for("effect-qb/Table/normalizedOptions");
110121
110119
  var options = Symbol.for("effect-qb/Table/declaredOptions");
110122
110120
  var CacheSymbol = Symbol.for("effect-qb/Table/cache");
110121
+ var SchemaCacheSymbol = Symbol.for("effect-qb/Table/schemaCache");
110123
110122
  var DeclaredOptionsSymbol = Symbol.for("effect-qb/Table/factoryDeclaredOptions");
110124
110123
  var TableProto = {
110125
110124
  pipe() {
@@ -110142,14 +110141,86 @@ var buildArtifacts = (name, fields2, declaredOptions, schemaName) => {
110142
110141
  validateOptions(name, fields2, declaredOptions);
110143
110142
  const primaryKey3 = resolvePrimaryKeyColumns(fields2, declaredOptions);
110144
110143
  const columns = Object.fromEntries(Object.entries(fields2).map(([key, column]) => [key, bindColumn(name, key, column, name, schemaName)]));
110145
- const schemas = deriveSchemas(name, fields2, primaryKey3);
110146
110144
  return {
110147
110145
  columns,
110148
- schemas,
110149
110146
  normalizedOptions,
110150
110147
  primaryKey: primaryKey3
110151
110148
  };
110152
110149
  };
110150
+ var getSchemaCache = (table) => {
110151
+ const target = table;
110152
+ if (target[SchemaCacheSymbol] !== undefined) {
110153
+ return target[SchemaCacheSymbol];
110154
+ }
110155
+ const cache = {};
110156
+ Object.defineProperty(table, SchemaCacheSymbol, {
110157
+ configurable: true,
110158
+ value: cache
110159
+ });
110160
+ return cache;
110161
+ };
110162
+ var deriveTableSchema = (table, variant) => {
110163
+ const state = table[TypeId4];
110164
+ switch (variant) {
110165
+ case "select":
110166
+ return deriveSelectSchema(state.name, state.fields, state.primaryKey);
110167
+ case "insert":
110168
+ return deriveInsertSchema(state.name, state.fields, state.primaryKey);
110169
+ case "update":
110170
+ return deriveUpdateSchema(state.name, state.fields, state.primaryKey);
110171
+ }
110172
+ };
110173
+ var schemaFor = (table, variant) => {
110174
+ const cache = getSchemaCache(table);
110175
+ const cached = cache[variant];
110176
+ if (cached !== undefined) {
110177
+ return cached;
110178
+ }
110179
+ const schema3 = deriveTableSchema(table, variant);
110180
+ cache[variant] = schema3;
110181
+ return schema3;
110182
+ };
110183
+ function selectSchema2(table) {
110184
+ return schemaFor(table, "select");
110185
+ }
110186
+ function insertSchema2(table) {
110187
+ return schemaFor(table, "insert");
110188
+ }
110189
+ function updateSchema2(table) {
110190
+ return schemaFor(table, "update");
110191
+ }
110192
+ var schemasFor = (table) => {
110193
+ const cache = getSchemaCache(table);
110194
+ if (cache.schemas !== undefined) {
110195
+ return cache.schemas;
110196
+ }
110197
+ const schemas = {};
110198
+ Object.defineProperties(schemas, {
110199
+ select: {
110200
+ enumerable: true,
110201
+ get: () => selectSchema2(table)
110202
+ },
110203
+ insert: {
110204
+ enumerable: true,
110205
+ get: () => insertSchema2(table)
110206
+ },
110207
+ update: {
110208
+ enumerable: true,
110209
+ get: () => updateSchema2(table)
110210
+ }
110211
+ });
110212
+ cache.schemas = schemas;
110213
+ return schemas;
110214
+ };
110215
+ var defineSchemasGetter = (table) => {
110216
+ Object.defineProperty(table, "schemas", {
110217
+ configurable: true,
110218
+ enumerable: true,
110219
+ get() {
110220
+ return schemasFor(table);
110221
+ }
110222
+ });
110223
+ };
110153
110224
  var makeTable = (name, fields2, declaredOptions, baseName = name, kind = "schema", schemaName, schemaMode = "default") => {
110154
110225
  const resolvedSchemaName = schemaMode === "explicit" ? schemaName : "public";
110155
110226
  const artifacts = buildArtifacts(name, fields2, declaredOptions, resolvedSchemaName);
@@ -110157,7 +110228,7 @@ var makeTable = (name, fields2, declaredOptions, baseName = name, kind = "schema
110157
110228
  const table = attachPipe2(Object.create(TableProto));
110158
110229
  table.name = name;
110159
110230
  table.columns = artifacts.columns;
110160
- table.schemas = artifacts.schemas;
110231
+ defineSchemasGetter(table);
110161
110232
  table[TypeId4] = {
110162
110233
  name,
110163
110234
  baseName,
@@ -110230,7 +110301,6 @@ var ensureClassArtifacts = (self) => {
110230
110301
  const table = applyDeclaredOptions(makeTable(state.name, state.fields, [], state.name, "schema", state.schemaName, state.schemaName === undefined || state.schemaName === "public" ? "default" : "explicit"), classOptions);
110231
110302
  const artifacts = {
110232
110303
  columns: table.columns,
110233
- schemas: table.schemas,
110234
110304
  normalizedOptions: table[OptionsSymbol],
110235
110305
  primaryKey: table[TypeId4].primaryKey
110236
110306
  };
@@ -110253,7 +110323,7 @@ var makeOption = (option) => {
110253
110323
  return builder;
110254
110324
  };
110255
110325
  var option = (spec) => makeOption(spec);
110256
- function make2(name, fields2, schemaName) {
110326
+ function make(name, fields2, schemaName) {
110257
110327
  const resolvedSchemaName = arguments.length >= 3 ? schemaName : "public";
110258
110328
  return makeTable(name, fields2, [], name, "schema", resolvedSchemaName, arguments.length >= 3 ? "explicit" : "default");
110259
110329
  }
@@ -110270,7 +110340,7 @@ var alias = (table, aliasName) => {
110270
110340
  const aliased = attachPipe2(Object.create(TableProto));
110271
110341
  aliased.name = aliasName;
110272
110342
  aliased.columns = columns;
110273
- aliased.schemas = deriveSchemas(aliasName, state.fields, state.primaryKey);
110343
+ defineSchemasGetter(aliased);
110274
110344
  aliased[TypeId4] = {
110275
110345
  name: aliasName,
110276
110346
  baseName: state.baseName,
@@ -110311,7 +110381,7 @@ function Class(name, schemaName) {
110311
110381
  return ensureClassArtifacts(this).columns;
110312
110382
  }
110313
110383
  static get schemas() {
110314
- return ensureClassArtifacts(this).schemas;
110384
+ return schemasFor(this);
110315
110385
  }
110316
110386
  static get [TypeId4]() {
110317
110387
  const declaredOptions = extractDeclaredOptions(this[options]);
@@ -110381,7 +110451,7 @@ var foreignKey2 = (columns, target, referencedColumns) => makeOption({
110381
110451
  knownColumns: Object.keys(target()[TypeId4].fields)
110382
110452
  })
110383
110453
  });
110384
- var check = (name, predicate) => makeOption({
110454
+ var check2 = (name, predicate) => makeOption({
110385
110455
  kind: "check",
110386
110456
  name,
110387
110457
  predicate
@@ -114871,20 +114941,21 @@ var exports_executor = {};
114871
114941
  __export(exports_executor, {
114872
114942
  withTransaction: () => withTransaction2,
114873
114943
  withSavepoint: () => withSavepoint2,
114874
- make: () => make6,
114944
+ make: () => make5,
114875
114945
  driver: () => driver2,
114876
114946
  custom: () => custom3
114877
114947
  });
114878
114948
  import * as Effect2 from "effect/Effect";
114879
- import * as SqlClient3 from "@effect/sql/SqlClient";
114949
+ import * as SqlClient3 from "effect/unstable/sql/SqlClient";
114880
114950
  import * as Stream2 from "effect/Stream";
114881
114951
 
114882
114952
  // src/internal/executor.ts
114883
114953
  import * as Chunk from "effect/Chunk";
114884
114954
  import * as Effect from "effect/Effect";
114955
+ import * as Exit from "effect/Exit";
114885
114956
  import * as Option from "effect/Option";
114886
114957
  import * as Schema9 from "effect/Schema";
114887
- import * as SqlClient from "@effect/sql/SqlClient";
114958
+ import * as SqlClient from "effect/unstable/sql/SqlClient";
114888
114959
  import * as Stream from "effect/Stream";
114889
114960
 
114890
114961
  // src/internal/runtime/driver-value-mapping.ts
@@ -115061,7 +115132,7 @@ var renderJsonSelectSql = (sql, context) => {
115061
115132
  import * as Schema8 from "effect/Schema";
115062
115133
  import * as SchemaAST from "effect/SchemaAST";
115063
115134
  var schemaCache = new WeakMap;
115064
- var FiniteNumberSchema = Schema8.Number.pipe(Schema8.finite());
115135
+ var FiniteNumberSchema = Schema8.Number.check(Schema8.isFinite());
115065
115136
  var runtimeSchemaForTag = (tag) => {
115066
115137
  switch (tag) {
115067
115138
  case "string":
@@ -115089,14 +115160,11 @@ var runtimeSchemaForTag = (tag) => {
115089
115160
  case "decimalString":
115090
115161
  return DecimalStringSchema;
115091
115162
  case "bytes":
115092
- return Schema8.Uint8ArrayFromSelf;
115163
+ return Schema8.Uint8Array;
115093
115164
  case "array":
115094
115165
  return Schema8.Array(Schema8.Unknown);
115095
115166
  case "record":
115096
- return Schema8.Record({
115097
- key: Schema8.String,
115098
- value: Schema8.Unknown
115099
- });
115167
+ return Schema8.Record(Schema8.String, Schema8.Unknown);
115100
115168
  case "null":
115101
115169
  return Schema8.Null;
115102
115170
  case "unknown":
@@ -115134,22 +115202,18 @@ var unionAst = (asts) => {
115134
115202
  if (asts.length === 1) {
115135
115203
  return asts[0];
115136
115204
  }
115137
- return SchemaAST.Union.make(asts);
115205
+ return new SchemaAST.Union(asts, "anyOf");
115138
115206
  };
115139
115207
  var propertyAstOf = (ast, key2) => {
115140
115208
  switch (ast._tag) {
115141
- case "Transformation":
115142
- return propertyAstOf(SchemaAST.typeAST(ast), key2);
115143
- case "Refinement":
115144
- return propertyAstOf(ast.from, key2);
115145
115209
  case "Suspend":
115146
- return propertyAstOf(ast.f(), key2);
115147
- case "TypeLiteral": {
115210
+ return propertyAstOf(ast.thunk(), key2);
115211
+ case "Objects": {
115148
115212
  const property = ast.propertySignatures.find((entry) => entry.name === key2);
115149
115213
  if (property !== undefined) {
115150
115214
  return property.type;
115151
115215
  }
115152
- const index4 = ast.indexSignatures.find((entry) => entry.parameter._tag === "StringKeyword");
115216
+ const index4 = ast.indexSignatures.find((entry) => entry.parameter._tag === "String");
115153
115217
  return index4?.type;
115154
115218
  }
115155
115219
  case "Union": {
@@ -115165,21 +115229,17 @@ var propertyAstOf = (ast, key2) => {
115165
115229
  };
115166
115230
  var numberAstOf = (ast, index4) => {
115167
115231
  switch (ast._tag) {
115168
- case "Transformation":
115169
- return numberAstOf(SchemaAST.typeAST(ast), index4);
115170
- case "Refinement":
115171
- return numberAstOf(ast.from, index4);
115172
115232
  case "Suspend":
115173
- return numberAstOf(ast.f(), index4);
115174
- case "TupleType": {
115233
+ return numberAstOf(ast.thunk(), index4);
115234
+ case "Arrays": {
115175
115235
  const element = ast.elements[index4];
115176
115236
  if (element !== undefined) {
115177
- return element.type;
115237
+ return element;
115178
115238
  }
115179
115239
  if (ast.rest.length === 0) {
115180
115240
  return;
115181
115241
  }
115182
- return unionAst(ast.rest.map((entry) => entry.type));
115242
+ return unionAst(ast.rest);
115183
115243
  }
115184
115244
  case "Union": {
115185
115245
  const values2 = ast.types.flatMap((member) => {
@@ -115194,7 +115254,7 @@ var numberAstOf = (ast, index4) => {
115194
115254
  };
115195
115255
  var exactJsonSegments = (segments) => segments.every((segment) => segment.kind === "key" || segment.kind === "index");
115196
115256
  var schemaAstAtExactJsonPath = (schema4, segments) => {
115197
- let current = SchemaAST.typeAST(schema4.ast);
115257
+ let current = schema4.ast;
115198
115258
  for (const segment of segments) {
115199
115259
  if (segment.kind === "key") {
115200
115260
  const property = propertyAstOf(current, segment.key);
@@ -115224,28 +115284,28 @@ var unionSchemas = (schemas) => {
115224
115284
  if (resolved.length === 1) {
115225
115285
  return resolved[0];
115226
115286
  }
115227
- return Schema8.Union(...resolved);
115287
+ return Schema8.Union(resolved);
115228
115288
  };
115229
115289
  var firstSelectedExpression = (plan) => {
115230
115290
  const selection = getAst(plan).select;
115231
115291
  return flattenSelection(selection)[0]?.expression;
115232
115292
  };
115233
115293
  var isJsonCompatibleAst = (ast) => {
115294
+ ast = SchemaAST.toType(ast);
115234
115295
  switch (ast._tag) {
115235
- case "StringKeyword":
115236
- case "NumberKeyword":
115237
- case "BooleanKeyword":
115238
- case "TupleType":
115239
- case "TypeLiteral":
115296
+ case "String":
115297
+ case "Number":
115298
+ case "Boolean":
115299
+ case "Null":
115300
+ case "Arrays":
115301
+ case "Objects":
115240
115302
  return true;
115241
115303
  case "Literal":
115242
- return ast.literal === null || typeof ast.literal === "string" || typeof ast.literal === "number" || typeof ast.literal === "boolean";
115304
+ return typeof ast.literal === "string" || typeof ast.literal === "number" || typeof ast.literal === "boolean";
115243
115305
  case "Union":
115244
115306
  return ast.types.every(isJsonCompatibleAst);
115245
- case "Transformation":
115246
- return isJsonCompatibleAst(SchemaAST.typeAST(ast));
115247
115307
  case "Suspend":
115248
- return isJsonCompatibleAst(ast.f());
115308
+ return isJsonCompatibleAst(ast.thunk());
115249
115309
  default:
115250
115310
  return false;
115251
115311
  }
@@ -115254,14 +115314,14 @@ var jsonCompatibleSchema = (schema4) => {
115254
115314
  if (schema4 === undefined) {
115255
115315
  return;
115256
115316
  }
115257
- const ast = SchemaAST.typeAST(schema4.ast);
115317
+ const ast = SchemaAST.toType(schema4.ast);
115258
115318
  return isJsonCompatibleAst(ast) ? schema4 : JsonValueSchema;
115259
115319
  };
115260
115320
  var buildStructSchema = (entries, context) => {
115261
115321
  const fields2 = Object.fromEntries(entries.map((entry) => [entry.key, expressionRuntimeSchema(entry.value, context) ?? JsonValueSchema]));
115262
115322
  return Schema8.Struct(fields2);
115263
115323
  };
115264
- var buildTupleSchema = (values2, context) => Schema8.Tuple(...values2.map((value) => expressionRuntimeSchema(value, context) ?? JsonValueSchema));
115324
+ var buildTupleSchema = (values2, context) => Schema8.Tuple(values2.map((value) => expressionRuntimeSchema(value, context) ?? JsonValueSchema));
115265
115325
  var deriveCaseSchema = (ast, context) => {
115266
115326
  if (context === undefined) {
115267
115327
  return unionSchemas([
@@ -115458,24 +115518,31 @@ var hasWriteCapability = (plan) => {
115458
115518
  }
115459
115519
  return false;
115460
115520
  };
115461
- var makeRowDecodeError = (rendered, projection, expression, raw, stage, cause, normalized) => ({
115462
- _tag: "RowDecodeError",
115463
- message: stage === "normalize" ? `Failed to normalize projection '${projection.alias}'` : `Failed to decode projection '${projection.alias}' against its runtime schema`,
115464
- dialect: rendered.dialect,
115465
- query: {
115466
- sql: rendered.sql,
115467
- params: rendered.params
115468
- },
115469
- projection: {
115470
- alias: projection.alias,
115471
- path: projection.path
115472
- },
115473
- dbType: expression[TypeId].dbType,
115474
- raw,
115475
- normalized,
115476
- stage,
115477
- cause
115478
- });
115521
+ var makeRowDecodeError = (rendered, projection, expression, raw, stage, cause, normalized) => {
115522
+ const schemaError = Schema9.isSchemaError(cause) ? {
115523
+ message: cause.message,
115524
+ issue: cause.issue
115525
+ } : undefined;
115526
+ return {
115527
+ _tag: "RowDecodeError",
115528
+ message: stage === "normalize" ? `Failed to normalize projection '${projection.alias}'` : `Failed to decode projection '${projection.alias}' against its runtime schema`,
115529
+ dialect: rendered.dialect,
115530
+ query: {
115531
+ sql: rendered.sql,
115532
+ params: rendered.params
115533
+ },
115534
+ projection: {
115535
+ alias: projection.alias,
115536
+ path: projection.path
115537
+ },
115538
+ dbType: expression[TypeId].dbType,
115539
+ raw,
115540
+ normalized,
115541
+ stage,
115542
+ cause,
115543
+ ...schemaError === undefined ? {} : { schemaError }
115544
+ };
115545
+ };
115479
115546
  var hasOptionalSourceDependency = (expression, scope) => {
115480
115547
  const state = expression[TypeId];
115481
115548
  return Object.keys(state.dependencies).some((sourceName) => !scope.absentSourceNames.has(sourceName) && scope.sourceModes.get(sourceName) === "optional");
@@ -115518,8 +115585,8 @@ var decodeProjectionValue = (rendered, projection, expression, raw, scope, drive
115518
115585
  driverValueMapping: expression[TypeId].driverValueMapping,
115519
115586
  valueMappings
115520
115587
  });
115521
- } catch (cause) {
115522
- throw makeRowDecodeError(rendered, projection, expression, raw, "normalize", cause);
115588
+ } catch (cause2) {
115589
+ throw makeRowDecodeError(rendered, projection, expression, raw, "normalize", cause2);
115523
115590
  }
115524
115591
  }
115525
115592
  const nullability = effectiveRuntimeNullability(expression, scope);
@@ -115545,11 +115612,15 @@ var decodeProjectionValue = (rendered, projection, expression, raw, scope, drive
115545
115612
  if (Schema9.is(schema4)(normalized)) {
115546
115613
  return normalized;
115547
115614
  }
115548
- try {
115549
- return Schema9.decodeUnknownSync(schema4)(normalized);
115550
- } catch (cause) {
115551
- throw makeRowDecodeError(rendered, projection, expression, raw, "schema", cause, normalized);
115615
+ const decoded = Schema9.decodeUnknownExit(schema4)(normalized);
115616
+ if (Exit.isSuccess(decoded)) {
115617
+ return decoded.value;
115552
115618
  }
115619
+ const cause = Option.match(Exit.findErrorOption(decoded), {
115620
+ onNone: () => decoded.cause,
115621
+ onSome: (schemaError) => schemaError
115622
+ });
115623
+ throw makeRowDecodeError(rendered, projection, expression, raw, "schema", cause, normalized);
115553
115624
  };
115554
115625
  var makeRowDecoder = (rendered, plan, options2 = {}) => {
115555
115626
  const projections = flattenSelection(getAst(plan).select);
@@ -115572,15 +115643,11 @@ var makeRowDecoder = (rendered, plan, options2 = {}) => {
115572
115643
  return decoded;
115573
115644
  };
115574
115645
  };
115575
- var decodeChunk = (rendered, plan, rows, options2 = {}) => {
115576
- const decodeRow = makeRowDecoder(rendered, plan, options2);
115577
- return Chunk.unsafeFromArray(Chunk.toReadonlyArray(rows).map((row) => decodeRow(row)));
115578
- };
115579
115646
  var decodeRows = (rendered, plan, rows, options2 = {}) => {
115580
115647
  const decodeRow = makeRowDecoder(rendered, plan, options2);
115581
115648
  return rows.map((row) => decodeRow(row));
115582
115649
  };
115583
- var make4 = (dialect, execute) => ({
115650
+ var make3 = (dialect, execute) => ({
115584
115651
  dialect,
115585
115652
  execute(plan) {
115586
115653
  return execute(plan);
@@ -115603,7 +115670,7 @@ function driver(dialect, executeOrHandlers) {
115603
115670
  }
115604
115671
  };
115605
115672
  }
115606
- var streamFromSqlClient = (query) => Stream.unwrapScoped(Effect.flatMap(SqlClient.SqlClient, (sql) => Effect.flatMap(Effect.serviceOption(SqlClient.TransactionConnection), Option.match({
115673
+ var streamFromSqlClient = (query) => Stream.unwrap(Effect.flatMap(SqlClient.SqlClient, (sql) => Effect.flatMap(Effect.serviceOption(sql.transactionService), Option.match({
115607
115674
  onNone: () => sql.reserve,
115608
115675
  onSome: ([connection]) => Effect.succeed(connection)
115609
115676
  })).pipe(Effect.map((connection) => connection.executeStream(query.sql, [...query.params], undefined)))));
@@ -115629,7 +115696,7 @@ var validateProjectionPathsMatchSelection = (plan, projections) => {
115629
115696
  }
115630
115697
  }
115631
115698
  };
115632
- function make5(dialect, render) {
115699
+ function make4(dialect, render) {
115633
115700
  if (typeof render !== "function") {
115634
115701
  throw new Error(`Renderer.make requires an explicit render implementation for dialect: ${dialect}`);
115635
115702
  }
@@ -117170,8 +117237,8 @@ var fromDriver = (renderer, sqlDriver, driverMode = "raw", valueMappings) => ({
117170
117237
  },
117171
117238
  stream(plan) {
117172
117239
  const rendered = renderer.render(plan);
117173
- return Stream2.mapError(Stream2.mapChunksEffect(sqlDriver.stream(rendered), (rows) => Effect2.try({
117174
- try: () => decodeChunk(rendered, plan, rows, { driverMode, valueMappings }),
117240
+ return Stream2.mapError(Stream2.mapArrayEffect(sqlDriver.stream(rendered), (rows) => Effect2.try({
117241
+ try: () => decodeRows(rendered, plan, rows, { driverMode, valueMappings }),
117175
117242
  catch: (error) => error
117176
117243
  })), (error) => {
117177
117244
  if (typeof error === "object" && error !== null && "_tag" in error && error._tag === "RowDecodeError") {
@@ -117186,13 +117253,13 @@ var sqlClientDriver = () => driver2({
117186
117253
  execute: (query) => Effect2.flatMap(SqlClient3.SqlClient, (sql) => sql.unsafe(query.sql, [...query.params])),
117187
117254
  stream: (query) => streamFromSqlClient(query)
117188
117255
  });
117189
- function make6(options2 = {}) {
117256
+ function make5(options2 = {}) {
117190
117257
  if (options2.driver) {
117191
- return fromDriver(options2.renderer ?? make5("mysql", (plan) => renderMysqlPlan(plan, { valueMappings: options2.valueMappings })), options2.driver, options2.driverMode, options2.valueMappings);
117258
+ return fromDriver(options2.renderer ?? make4("mysql", (plan) => renderMysqlPlan(plan, { valueMappings: options2.valueMappings })), options2.driver, options2.driverMode, options2.valueMappings);
117192
117259
  }
117193
- return fromDriver(options2.renderer ?? make5("mysql", (plan) => renderMysqlPlan(plan, { valueMappings: options2.valueMappings })), sqlClientDriver(), options2.driverMode, options2.valueMappings);
117260
+ return fromDriver(options2.renderer ?? make4("mysql", (plan) => renderMysqlPlan(plan, { valueMappings: options2.valueMappings })), sqlClientDriver(), options2.driverMode, options2.valueMappings);
117194
117261
  }
117195
- var custom3 = (execute) => make4("mysql", execute);
117262
+ var custom3 = (execute) => make3("mysql", execute);
117196
117263
  // src/mysql/query.ts
117197
117264
  var exports_query2 = {};
117198
117265
  __export(exports_query2, {
@@ -117288,14 +117355,17 @@ var from2 = exportedFrom;
117288
117355
  // src/mysql/table.ts
117289
117356
  var exports_table2 = {};
117290
117357
  __export(exports_table2, {
117358
+ updateSchema: () => updateSchema3,
117291
117359
  unique: () => unique4,
117360
+ selectSchema: () => selectSchema3,
117292
117361
  schema: () => schema4,
117293
117362
  primaryKey: () => primaryKey4,
117294
117363
  options: () => options2,
117295
- make: () => make7,
117364
+ make: () => make6,
117365
+ insertSchema: () => insertSchema3,
117296
117366
  index: () => index4,
117297
117367
  foreignKey: () => foreignKey3,
117298
- check: () => check2,
117368
+ check: () => check3,
117299
117369
  alias: () => alias2,
117300
117370
  TypeId: () => TypeId10,
117301
117371
  OptionsSymbol: () => OptionsSymbol2,
@@ -117304,7 +117374,7 @@ __export(exports_table2, {
117304
117374
  var TypeId10 = TypeId4;
117305
117375
  var OptionsSymbol2 = OptionsSymbol;
117306
117376
  var options2 = options;
117307
- var make7 = (name, fields2, schemaName = undefined) => make2(name, fields2, schemaName);
117377
+ var make6 = (name, fields2, schemaName = undefined) => make(name, fields2, schemaName);
117308
117378
  var schema4 = (schemaName) => {
117309
117379
  const table = (name, fields2, ...declaredOptions) => schema3(schemaName).table(name, fields2, ...declaredOptions);
117310
117380
  return {
@@ -117321,16 +117391,19 @@ var primaryKey4 = primaryKey3;
117321
117391
  var unique4 = unique3;
117322
117392
  var index4 = index2;
117323
117393
  var foreignKey3 = (columns, target, referencedColumns) => foreignKey2(columns, target, referencedColumns);
117324
- var check2 = check;
117394
+ var check3 = check2;
117395
+ var selectSchema3 = selectSchema2;
117396
+ var insertSchema3 = insertSchema2;
117397
+ var updateSchema3 = updateSchema2;
117325
117398
  // src/mysql/renderer.ts
117326
117399
  var exports_renderer2 = {};
117327
117400
  __export(exports_renderer2, {
117328
117401
  mysql: () => mysql,
117329
- make: () => make8,
117402
+ make: () => make7,
117330
117403
  TypeId: () => TypeId8
117331
117404
  });
117332
- var make8 = (options3 = {}) => make5("mysql", (plan) => renderMysqlPlan(plan, options3));
117333
- var mysql = make8();
117405
+ var make7 = (options3 = {}) => make4("mysql", (plan) => renderMysqlPlan(plan, options3));
117406
+ var mysql = make7();
117334
117407
  export {
117335
117408
  exports_table2 as Table,
117336
117409
  exports_scalar as Scalar,