@onyx.dev/onyx-database 0.3.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -743,7 +743,7 @@ interface ICascadeBuilder<Schema = Record<string, unknown>> {
743
743
  * await db.cascade('permissions').delete('Role', 'admin');
744
744
  * ```
745
745
  */
746
- delete<Table extends keyof Schema & string>(table: Table, primaryKey: string): Promise<Schema[Table]>;
746
+ delete<Table extends keyof Schema & string>(table: Table, primaryKey: string): Promise<boolean>;
747
747
  }
748
748
  /** Builder for describing cascade relationship metadata. */
749
749
  interface ICascadeRelationshipBuilder {
@@ -970,11 +970,12 @@ interface IOnyxDatabase<Schema = Record<string, unknown>> {
970
970
  * @param table Table containing the entity.
971
971
  * @param primaryKey Primary key value.
972
972
  * @param options Optional partition and cascade relationships.
973
+ * @returns `true` when the delete request succeeds.
973
974
  */
974
- delete<Table extends keyof Schema & string, T = Schema[Table]>(table: Table, primaryKey: string, options?: {
975
+ delete<Table extends keyof Schema & string>(table: Table, primaryKey: string, options?: {
975
976
  partition?: string;
976
977
  relationships?: string[];
977
- }): Promise<T>;
978
+ }): Promise<boolean>;
978
979
  /**
979
980
  * Store a document (file blob) for later retrieval.
980
981
  *
@@ -1030,6 +1031,18 @@ interface IOnyxDatabase<Schema = Record<string, unknown>> {
1030
1031
  * Retrieve the schema revision history for the configured database.
1031
1032
  */
1032
1033
  getSchemaHistory(): Promise<SchemaHistoryEntry[]>;
1034
+ /**
1035
+ * Compare the current API schema with a local schema definition.
1036
+ *
1037
+ * @example
1038
+ * ```ts
1039
+ * const diff = await db.diffSchema(localSchema);
1040
+ * if (!diff.newTables.length && !diff.removedTables.length && !diff.changedTables.length) {
1041
+ * console.log('Schemas match');
1042
+ * }
1043
+ * ```
1044
+ */
1045
+ diffSchema(localSchema: SchemaUpsertRequest): Promise<SchemaDiff>;
1033
1046
  /**
1034
1047
  * Update the schema for the configured database.
1035
1048
  *
@@ -1148,16 +1161,19 @@ interface SchemaIndex {
1148
1161
  name: string;
1149
1162
  type?: SchemaIndexType;
1150
1163
  minimumScore?: number;
1164
+ [key: string]: unknown;
1151
1165
  }
1152
1166
  interface SchemaResolver {
1153
1167
  name: string;
1154
1168
  resolver: string;
1169
+ [key: string]: unknown;
1155
1170
  }
1156
1171
  type SchemaTriggerEvent = 'PreInsert' | 'PostInsert' | 'PrePersist' | 'PostPersist' | 'PreUpdate' | 'PostUpdate' | 'PreDelete' | 'PostDelete' | string;
1157
1172
  interface SchemaTrigger {
1158
1173
  name: string;
1159
1174
  event: SchemaTriggerEvent;
1160
1175
  trigger: string;
1176
+ [key: string]: unknown;
1161
1177
  }
1162
1178
  interface SchemaEntity {
1163
1179
  name: string;
@@ -1167,21 +1183,25 @@ interface SchemaEntity {
1167
1183
  indexes?: SchemaIndex[];
1168
1184
  resolvers?: SchemaResolver[];
1169
1185
  triggers?: SchemaTrigger[];
1186
+ [key: string]: unknown;
1170
1187
  }
1171
1188
  interface SchemaRevisionMetadata {
1172
1189
  revisionId?: string;
1173
1190
  createdAt?: Date;
1174
1191
  publishedAt?: Date;
1192
+ [key: string]: unknown;
1175
1193
  }
1176
1194
  interface SchemaRevision {
1177
1195
  databaseId: string;
1178
1196
  revisionDescription?: string;
1179
1197
  entities: SchemaEntity[];
1180
1198
  meta?: SchemaRevisionMetadata;
1199
+ [key: string]: unknown;
1181
1200
  }
1182
1201
  type SchemaHistoryEntry = SchemaRevision;
1183
1202
  type SchemaUpsertRequest = Omit<SchemaRevision, 'databaseId' | 'meta'> & {
1184
1203
  databaseId?: string;
1204
+ [key: string]: unknown;
1185
1205
  };
1186
1206
  interface SchemaValidationResult {
1187
1207
  valid?: boolean;
@@ -1190,6 +1210,68 @@ interface SchemaValidationResult {
1190
1210
  message: string;
1191
1211
  }>;
1192
1212
  }
1213
+ interface SchemaAttributeChange {
1214
+ name: string;
1215
+ from: {
1216
+ type?: string;
1217
+ isNullable?: boolean;
1218
+ };
1219
+ to: {
1220
+ type?: string;
1221
+ isNullable?: boolean;
1222
+ };
1223
+ }
1224
+ interface SchemaIndexChange {
1225
+ name: string;
1226
+ from: SchemaIndex;
1227
+ to: SchemaIndex;
1228
+ }
1229
+ interface SchemaResolverChange {
1230
+ name: string;
1231
+ from: SchemaResolver;
1232
+ to: SchemaResolver;
1233
+ }
1234
+ interface SchemaTriggerChange {
1235
+ name: string;
1236
+ from: SchemaTrigger;
1237
+ to: SchemaTrigger;
1238
+ }
1239
+ interface SchemaTableDiff {
1240
+ name: string;
1241
+ partition?: {
1242
+ from: string | null;
1243
+ to: string | null;
1244
+ } | null;
1245
+ identifier?: {
1246
+ from: SchemaIdentifier | null;
1247
+ to: SchemaIdentifier | null;
1248
+ } | null;
1249
+ attributes?: {
1250
+ added: SchemaAttribute[];
1251
+ removed: string[];
1252
+ changed: SchemaAttributeChange[];
1253
+ };
1254
+ indexes?: {
1255
+ added: SchemaIndex[];
1256
+ removed: string[];
1257
+ changed: SchemaIndexChange[];
1258
+ };
1259
+ resolvers?: {
1260
+ added: SchemaResolver[];
1261
+ removed: string[];
1262
+ changed: SchemaResolverChange[];
1263
+ };
1264
+ triggers?: {
1265
+ added: SchemaTrigger[];
1266
+ removed: string[];
1267
+ changed: SchemaTriggerChange[];
1268
+ };
1269
+ }
1270
+ interface SchemaDiff {
1271
+ newTables: string[];
1272
+ removedTables: string[];
1273
+ changedTables: SchemaTableDiff[];
1274
+ }
1193
1275
 
1194
1276
  /** -------------------------
1195
1277
  * Facade export
@@ -1287,8 +1369,12 @@ declare class ConditionBuilderImpl implements IConditionBuilder {
1287
1369
 
1288
1370
  declare const eq: (field: string, value: unknown) => ConditionBuilderImpl;
1289
1371
  declare const neq: (field: string, value: unknown) => ConditionBuilderImpl;
1290
- declare const inOp: (field: string, values: unknown[] | string) => ConditionBuilderImpl;
1291
- declare const notIn: (field: string, values: unknown[]) => ConditionBuilderImpl;
1372
+ declare function inOp(field: string, values: string): ConditionBuilderImpl;
1373
+ declare function inOp<T>(field: string, values: unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1374
+ declare function within<T>(field: string, values: string | unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1375
+ declare function notIn(field: string, values: string): ConditionBuilderImpl;
1376
+ declare function notIn<T>(field: string, values: unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1377
+ declare function notWithin<T>(field: string, values: string | unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1292
1378
  declare const between: (field: string, lower: unknown, upper: unknown) => ConditionBuilderImpl;
1293
1379
  declare const gt: (field: string, value: unknown) => ConditionBuilderImpl;
1294
1380
  declare const gte: (field: string, value: unknown) => ConditionBuilderImpl;
@@ -1324,4 +1410,4 @@ declare const percentile: (attribute: string, p: number) => string;
1324
1410
  declare const sdkName = "@onyx.dev/onyx-database";
1325
1411
  declare const sdkVersion = "0.1.0";
1326
1412
 
1327
- export { type FetchImpl, type FetchResponse, type ICascadeBuilder, type ICascadeRelationshipBuilder, type IConditionBuilder, type IOnyxDatabase, type IQueryBuilder, type ISaveBuilder, type LogicalOperator, type OnyxConfig, type OnyxDocument, type OnyxFacade, type QueryCondition, type QueryCriteria, type QueryCriteriaOperator, type QueryPage, QueryResults, type QueryResultsPromise, type SchemaAttribute, type SchemaDataType, type SchemaEntity, type SchemaHistoryEntry, type SchemaIdentifier, type SchemaIdentifierGenerator, type SchemaIndex, type SchemaIndexType, type SchemaResolver, type SchemaRevision, type SchemaRevisionMetadata, type SchemaTrigger, type SchemaTriggerEvent, type SchemaUpsertRequest, type SchemaValidationResult, type SecretMetadata, type SecretRecord, type SecretSaveRequest, type SecretsListResponse, type SelectQuery, type Sort, type StreamAction, type UpdateQuery, asc, avg, between, contains, containsIgnoreCase, count, desc, eq, gt, gte, inOp, isNull, like, lower, lt, lte, matches, max, median, min, neq, notContains, notContainsIgnoreCase, notIn, notLike, notMatches, notNull, notStartsWith, onyx, percentile, replace, sdkName, sdkVersion, startsWith, std, substring, sum, upper, variance };
1413
+ export { type FetchImpl, type FetchResponse, type ICascadeBuilder, type ICascadeRelationshipBuilder, type IConditionBuilder, type IOnyxDatabase, type IQueryBuilder, type ISaveBuilder, type LogicalOperator, type OnyxConfig, type OnyxDocument, type OnyxFacade, type QueryCondition, type QueryCriteria, type QueryCriteriaOperator, type QueryPage, QueryResults, type QueryResultsPromise, type SchemaAttribute, type SchemaAttributeChange, type SchemaDataType, type SchemaDiff, type SchemaEntity, type SchemaHistoryEntry, type SchemaIdentifier, type SchemaIdentifierGenerator, type SchemaIndex, type SchemaIndexChange, type SchemaIndexType, type SchemaResolver, type SchemaResolverChange, type SchemaRevision, type SchemaRevisionMetadata, type SchemaTableDiff, type SchemaTrigger, type SchemaTriggerChange, type SchemaTriggerEvent, type SchemaUpsertRequest, type SchemaValidationResult, type SecretMetadata, type SecretRecord, type SecretSaveRequest, type SecretsListResponse, type SelectQuery, type Sort, type StreamAction, type UpdateQuery, asc, avg, between, contains, containsIgnoreCase, count, desc, eq, gt, gte, inOp, isNull, like, lower, lt, lte, matches, max, median, min, neq, notContains, notContainsIgnoreCase, notIn, notLike, notMatches, notNull, notStartsWith, notWithin, onyx, percentile, replace, sdkName, sdkVersion, startsWith, std, substring, sum, upper, variance, within };
package/dist/index.d.ts CHANGED
@@ -743,7 +743,7 @@ interface ICascadeBuilder<Schema = Record<string, unknown>> {
743
743
  * await db.cascade('permissions').delete('Role', 'admin');
744
744
  * ```
745
745
  */
746
- delete<Table extends keyof Schema & string>(table: Table, primaryKey: string): Promise<Schema[Table]>;
746
+ delete<Table extends keyof Schema & string>(table: Table, primaryKey: string): Promise<boolean>;
747
747
  }
748
748
  /** Builder for describing cascade relationship metadata. */
749
749
  interface ICascadeRelationshipBuilder {
@@ -970,11 +970,12 @@ interface IOnyxDatabase<Schema = Record<string, unknown>> {
970
970
  * @param table Table containing the entity.
971
971
  * @param primaryKey Primary key value.
972
972
  * @param options Optional partition and cascade relationships.
973
+ * @returns `true` when the delete request succeeds.
973
974
  */
974
- delete<Table extends keyof Schema & string, T = Schema[Table]>(table: Table, primaryKey: string, options?: {
975
+ delete<Table extends keyof Schema & string>(table: Table, primaryKey: string, options?: {
975
976
  partition?: string;
976
977
  relationships?: string[];
977
- }): Promise<T>;
978
+ }): Promise<boolean>;
978
979
  /**
979
980
  * Store a document (file blob) for later retrieval.
980
981
  *
@@ -1030,6 +1031,18 @@ interface IOnyxDatabase<Schema = Record<string, unknown>> {
1030
1031
  * Retrieve the schema revision history for the configured database.
1031
1032
  */
1032
1033
  getSchemaHistory(): Promise<SchemaHistoryEntry[]>;
1034
+ /**
1035
+ * Compare the current API schema with a local schema definition.
1036
+ *
1037
+ * @example
1038
+ * ```ts
1039
+ * const diff = await db.diffSchema(localSchema);
1040
+ * if (!diff.newTables.length && !diff.removedTables.length && !diff.changedTables.length) {
1041
+ * console.log('Schemas match');
1042
+ * }
1043
+ * ```
1044
+ */
1045
+ diffSchema(localSchema: SchemaUpsertRequest): Promise<SchemaDiff>;
1033
1046
  /**
1034
1047
  * Update the schema for the configured database.
1035
1048
  *
@@ -1148,16 +1161,19 @@ interface SchemaIndex {
1148
1161
  name: string;
1149
1162
  type?: SchemaIndexType;
1150
1163
  minimumScore?: number;
1164
+ [key: string]: unknown;
1151
1165
  }
1152
1166
  interface SchemaResolver {
1153
1167
  name: string;
1154
1168
  resolver: string;
1169
+ [key: string]: unknown;
1155
1170
  }
1156
1171
  type SchemaTriggerEvent = 'PreInsert' | 'PostInsert' | 'PrePersist' | 'PostPersist' | 'PreUpdate' | 'PostUpdate' | 'PreDelete' | 'PostDelete' | string;
1157
1172
  interface SchemaTrigger {
1158
1173
  name: string;
1159
1174
  event: SchemaTriggerEvent;
1160
1175
  trigger: string;
1176
+ [key: string]: unknown;
1161
1177
  }
1162
1178
  interface SchemaEntity {
1163
1179
  name: string;
@@ -1167,21 +1183,25 @@ interface SchemaEntity {
1167
1183
  indexes?: SchemaIndex[];
1168
1184
  resolvers?: SchemaResolver[];
1169
1185
  triggers?: SchemaTrigger[];
1186
+ [key: string]: unknown;
1170
1187
  }
1171
1188
  interface SchemaRevisionMetadata {
1172
1189
  revisionId?: string;
1173
1190
  createdAt?: Date;
1174
1191
  publishedAt?: Date;
1192
+ [key: string]: unknown;
1175
1193
  }
1176
1194
  interface SchemaRevision {
1177
1195
  databaseId: string;
1178
1196
  revisionDescription?: string;
1179
1197
  entities: SchemaEntity[];
1180
1198
  meta?: SchemaRevisionMetadata;
1199
+ [key: string]: unknown;
1181
1200
  }
1182
1201
  type SchemaHistoryEntry = SchemaRevision;
1183
1202
  type SchemaUpsertRequest = Omit<SchemaRevision, 'databaseId' | 'meta'> & {
1184
1203
  databaseId?: string;
1204
+ [key: string]: unknown;
1185
1205
  };
1186
1206
  interface SchemaValidationResult {
1187
1207
  valid?: boolean;
@@ -1190,6 +1210,68 @@ interface SchemaValidationResult {
1190
1210
  message: string;
1191
1211
  }>;
1192
1212
  }
1213
+ interface SchemaAttributeChange {
1214
+ name: string;
1215
+ from: {
1216
+ type?: string;
1217
+ isNullable?: boolean;
1218
+ };
1219
+ to: {
1220
+ type?: string;
1221
+ isNullable?: boolean;
1222
+ };
1223
+ }
1224
+ interface SchemaIndexChange {
1225
+ name: string;
1226
+ from: SchemaIndex;
1227
+ to: SchemaIndex;
1228
+ }
1229
+ interface SchemaResolverChange {
1230
+ name: string;
1231
+ from: SchemaResolver;
1232
+ to: SchemaResolver;
1233
+ }
1234
+ interface SchemaTriggerChange {
1235
+ name: string;
1236
+ from: SchemaTrigger;
1237
+ to: SchemaTrigger;
1238
+ }
1239
+ interface SchemaTableDiff {
1240
+ name: string;
1241
+ partition?: {
1242
+ from: string | null;
1243
+ to: string | null;
1244
+ } | null;
1245
+ identifier?: {
1246
+ from: SchemaIdentifier | null;
1247
+ to: SchemaIdentifier | null;
1248
+ } | null;
1249
+ attributes?: {
1250
+ added: SchemaAttribute[];
1251
+ removed: string[];
1252
+ changed: SchemaAttributeChange[];
1253
+ };
1254
+ indexes?: {
1255
+ added: SchemaIndex[];
1256
+ removed: string[];
1257
+ changed: SchemaIndexChange[];
1258
+ };
1259
+ resolvers?: {
1260
+ added: SchemaResolver[];
1261
+ removed: string[];
1262
+ changed: SchemaResolverChange[];
1263
+ };
1264
+ triggers?: {
1265
+ added: SchemaTrigger[];
1266
+ removed: string[];
1267
+ changed: SchemaTriggerChange[];
1268
+ };
1269
+ }
1270
+ interface SchemaDiff {
1271
+ newTables: string[];
1272
+ removedTables: string[];
1273
+ changedTables: SchemaTableDiff[];
1274
+ }
1193
1275
 
1194
1276
  /** -------------------------
1195
1277
  * Facade export
@@ -1287,8 +1369,12 @@ declare class ConditionBuilderImpl implements IConditionBuilder {
1287
1369
 
1288
1370
  declare const eq: (field: string, value: unknown) => ConditionBuilderImpl;
1289
1371
  declare const neq: (field: string, value: unknown) => ConditionBuilderImpl;
1290
- declare const inOp: (field: string, values: unknown[] | string) => ConditionBuilderImpl;
1291
- declare const notIn: (field: string, values: unknown[]) => ConditionBuilderImpl;
1372
+ declare function inOp(field: string, values: string): ConditionBuilderImpl;
1373
+ declare function inOp<T>(field: string, values: unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1374
+ declare function within<T>(field: string, values: string | unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1375
+ declare function notIn(field: string, values: string): ConditionBuilderImpl;
1376
+ declare function notIn<T>(field: string, values: unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1377
+ declare function notWithin<T>(field: string, values: string | unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1292
1378
  declare const between: (field: string, lower: unknown, upper: unknown) => ConditionBuilderImpl;
1293
1379
  declare const gt: (field: string, value: unknown) => ConditionBuilderImpl;
1294
1380
  declare const gte: (field: string, value: unknown) => ConditionBuilderImpl;
@@ -1324,4 +1410,4 @@ declare const percentile: (attribute: string, p: number) => string;
1324
1410
  declare const sdkName = "@onyx.dev/onyx-database";
1325
1411
  declare const sdkVersion = "0.1.0";
1326
1412
 
1327
- export { type FetchImpl, type FetchResponse, type ICascadeBuilder, type ICascadeRelationshipBuilder, type IConditionBuilder, type IOnyxDatabase, type IQueryBuilder, type ISaveBuilder, type LogicalOperator, type OnyxConfig, type OnyxDocument, type OnyxFacade, type QueryCondition, type QueryCriteria, type QueryCriteriaOperator, type QueryPage, QueryResults, type QueryResultsPromise, type SchemaAttribute, type SchemaDataType, type SchemaEntity, type SchemaHistoryEntry, type SchemaIdentifier, type SchemaIdentifierGenerator, type SchemaIndex, type SchemaIndexType, type SchemaResolver, type SchemaRevision, type SchemaRevisionMetadata, type SchemaTrigger, type SchemaTriggerEvent, type SchemaUpsertRequest, type SchemaValidationResult, type SecretMetadata, type SecretRecord, type SecretSaveRequest, type SecretsListResponse, type SelectQuery, type Sort, type StreamAction, type UpdateQuery, asc, avg, between, contains, containsIgnoreCase, count, desc, eq, gt, gte, inOp, isNull, like, lower, lt, lte, matches, max, median, min, neq, notContains, notContainsIgnoreCase, notIn, notLike, notMatches, notNull, notStartsWith, onyx, percentile, replace, sdkName, sdkVersion, startsWith, std, substring, sum, upper, variance };
1413
+ export { type FetchImpl, type FetchResponse, type ICascadeBuilder, type ICascadeRelationshipBuilder, type IConditionBuilder, type IOnyxDatabase, type IQueryBuilder, type ISaveBuilder, type LogicalOperator, type OnyxConfig, type OnyxDocument, type OnyxFacade, type QueryCondition, type QueryCriteria, type QueryCriteriaOperator, type QueryPage, QueryResults, type QueryResultsPromise, type SchemaAttribute, type SchemaAttributeChange, type SchemaDataType, type SchemaDiff, type SchemaEntity, type SchemaHistoryEntry, type SchemaIdentifier, type SchemaIdentifierGenerator, type SchemaIndex, type SchemaIndexChange, type SchemaIndexType, type SchemaResolver, type SchemaResolverChange, type SchemaRevision, type SchemaRevisionMetadata, type SchemaTableDiff, type SchemaTrigger, type SchemaTriggerChange, type SchemaTriggerEvent, type SchemaUpsertRequest, type SchemaValidationResult, type SecretMetadata, type SecretRecord, type SecretSaveRequest, type SecretsListResponse, type SelectQuery, type Sort, type StreamAction, type UpdateQuery, asc, avg, between, contains, containsIgnoreCase, count, desc, eq, gt, gte, inOp, isNull, like, lower, lt, lte, matches, max, median, min, neq, notContains, notContainsIgnoreCase, notIn, notLike, notMatches, notNull, notStartsWith, notWithin, onyx, percentile, replace, sdkName, sdkVersion, startsWith, std, substring, sum, upper, variance, within };