@onyx.dev/onyx-database 0.3.0 → 1.0.0

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
@@ -1287,8 +1287,12 @@ declare class ConditionBuilderImpl implements IConditionBuilder {
1287
1287
 
1288
1288
  declare const eq: (field: string, value: unknown) => ConditionBuilderImpl;
1289
1289
  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;
1290
+ declare function inOp(field: string, values: string): ConditionBuilderImpl;
1291
+ declare function inOp<T>(field: string, values: unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1292
+ declare function within<T>(field: string, values: string | unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1293
+ declare function notIn(field: string, values: string): ConditionBuilderImpl;
1294
+ declare function notIn<T>(field: string, values: unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1295
+ declare function notWithin<T>(field: string, values: string | unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1292
1296
  declare const between: (field: string, lower: unknown, upper: unknown) => ConditionBuilderImpl;
1293
1297
  declare const gt: (field: string, value: unknown) => ConditionBuilderImpl;
1294
1298
  declare const gte: (field: string, value: unknown) => ConditionBuilderImpl;
@@ -1324,4 +1328,4 @@ declare const percentile: (attribute: string, p: number) => string;
1324
1328
  declare const sdkName = "@onyx.dev/onyx-database";
1325
1329
  declare const sdkVersion = "0.1.0";
1326
1330
 
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 };
1331
+ 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, notWithin, onyx, percentile, replace, sdkName, sdkVersion, startsWith, std, substring, sum, upper, variance, within };
package/dist/index.d.ts CHANGED
@@ -1287,8 +1287,12 @@ declare class ConditionBuilderImpl implements IConditionBuilder {
1287
1287
 
1288
1288
  declare const eq: (field: string, value: unknown) => ConditionBuilderImpl;
1289
1289
  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;
1290
+ declare function inOp(field: string, values: string): ConditionBuilderImpl;
1291
+ declare function inOp<T>(field: string, values: unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1292
+ declare function within<T>(field: string, values: string | unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1293
+ declare function notIn(field: string, values: string): ConditionBuilderImpl;
1294
+ declare function notIn<T>(field: string, values: unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1295
+ declare function notWithin<T>(field: string, values: string | unknown[] | IQueryBuilder<T>): ConditionBuilderImpl;
1292
1296
  declare const between: (field: string, lower: unknown, upper: unknown) => ConditionBuilderImpl;
1293
1297
  declare const gt: (field: string, value: unknown) => ConditionBuilderImpl;
1294
1298
  declare const gte: (field: string, value: unknown) => ConditionBuilderImpl;
@@ -1324,4 +1328,4 @@ declare const percentile: (attribute: string, p: number) => string;
1324
1328
  declare const sdkName = "@onyx.dev/onyx-database";
1325
1329
  declare const sdkVersion = "0.1.0";
1326
1330
 
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 };
1331
+ 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, notWithin, onyx, percentile, replace, sdkName, sdkVersion, startsWith, std, substring, sum, upper, variance, within };
package/dist/index.js CHANGED
@@ -831,6 +831,56 @@ var QueryResults = class extends Array {
831
831
  }
832
832
  };
833
833
 
834
+ // src/helpers/condition-normalizer.ts
835
+ function isQueryBuilderLike(value) {
836
+ return !!value && typeof value.toSerializableQueryObject === "function";
837
+ }
838
+ function normalizeCriteriaValue(value) {
839
+ if (Array.isArray(value)) {
840
+ let changed = false;
841
+ const normalized = value.map((item) => {
842
+ const result = normalizeCriteriaValue(item);
843
+ if (result.changed) changed = true;
844
+ return result.value;
845
+ });
846
+ if (!changed) {
847
+ for (let i = 0; i < normalized.length; i += 1) {
848
+ if (normalized[i] !== value[i]) {
849
+ changed = true;
850
+ break;
851
+ }
852
+ }
853
+ }
854
+ return { value: changed ? normalized : value, changed };
855
+ }
856
+ if (isQueryBuilderLike(value)) {
857
+ return { value: value.toSerializableQueryObject(), changed: true };
858
+ }
859
+ return { value, changed: false };
860
+ }
861
+ function normalizeConditionInternal(condition) {
862
+ if (condition.conditionType === "SingleCondition") {
863
+ const { value, changed: changed2 } = normalizeCriteriaValue(condition.criteria.value);
864
+ if (!changed2) return condition;
865
+ return {
866
+ ...condition,
867
+ criteria: { ...condition.criteria, value }
868
+ };
869
+ }
870
+ let changed = false;
871
+ const normalizedConditions = condition.conditions.map((child) => {
872
+ const normalized = normalizeConditionInternal(child);
873
+ if (normalized !== child) changed = true;
874
+ return normalized;
875
+ });
876
+ if (!changed) return condition;
877
+ return { ...condition, conditions: normalizedConditions };
878
+ }
879
+ function normalizeCondition(condition) {
880
+ if (!condition) return condition;
881
+ return normalizeConditionInternal(condition);
882
+ }
883
+
834
884
  // src/builders/cascade-relationship-builder.ts
835
885
  var CascadeRelationshipBuilder = class {
836
886
  graphName;
@@ -958,6 +1008,10 @@ function serializeDates(value) {
958
1008
  }
959
1009
  return value;
960
1010
  }
1011
+ function stripEntityText(input) {
1012
+ const { entityText, ...rest } = input;
1013
+ return rest;
1014
+ }
961
1015
  function normalizeSecretMetadata(input) {
962
1016
  return { ...input, updatedAt: new Date(input.updatedAt) };
963
1017
  }
@@ -971,7 +1025,7 @@ function normalizeDate(value) {
971
1025
  return Number.isNaN(ts.getTime()) ? void 0 : ts;
972
1026
  }
973
1027
  function normalizeSchemaRevision(input, fallbackDatabaseId) {
974
- const { meta, createdAt, publishedAt, revisionId, ...rest } = input;
1028
+ const { meta, createdAt, publishedAt, revisionId, entityText, ...rest } = input;
975
1029
  const mergedMeta = {
976
1030
  revisionId: meta?.revisionId ?? revisionId,
977
1031
  createdAt: normalizeDate(meta?.createdAt ?? createdAt),
@@ -1142,15 +1196,23 @@ var OnyxDatabaseImpl = class {
1142
1196
  const params = new URLSearchParams();
1143
1197
  if (options?.publish) params.append("publish", "true");
1144
1198
  const path = `/schemas/${encodeURIComponent(databaseId)}${params.size ? `?${params.toString()}` : ""}`;
1145
- const body = { ...schema, databaseId: schema.databaseId ?? databaseId };
1146
- const res = await http.request("PUT", path, serializeDates(body));
1199
+ const body = stripEntityText({ ...schema, databaseId: schema.databaseId ?? databaseId });
1200
+ const res = await http.request(
1201
+ "PUT",
1202
+ path,
1203
+ serializeDates(body)
1204
+ );
1147
1205
  return normalizeSchemaRevision(res, databaseId);
1148
1206
  }
1149
1207
  async validateSchema(schema) {
1150
1208
  const { http, databaseId } = await this.ensureClient();
1151
1209
  const path = `/schemas/${encodeURIComponent(databaseId)}/validate`;
1152
- const body = { ...schema, databaseId: schema.databaseId ?? databaseId };
1153
- const res = await http.request("POST", path, serializeDates(body));
1210
+ const body = stripEntityText({ ...schema, databaseId: schema.databaseId ?? databaseId });
1211
+ const res = await http.request(
1212
+ "POST",
1213
+ path,
1214
+ serializeDates(body)
1215
+ );
1154
1216
  const normalizedSchema = res.schema ? normalizeSchemaRevision(res.schema, databaseId) : void 0;
1155
1217
  return {
1156
1218
  ...res,
@@ -1312,11 +1374,14 @@ var QueryBuilderImpl = class {
1312
1374
  if (!this.table) throw new Error("Table is not defined. Call from(<table>) first.");
1313
1375
  return this.table;
1314
1376
  }
1377
+ serializableConditions() {
1378
+ return normalizeCondition(this.conditions);
1379
+ }
1315
1380
  toSelectQuery() {
1316
1381
  return {
1317
1382
  type: "SelectQuery",
1318
1383
  fields: this.fields,
1319
- conditions: this.conditions,
1384
+ conditions: this.serializableConditions(),
1320
1385
  sort: this.sort,
1321
1386
  limit: this.limitValue,
1322
1387
  distinct: this.distinctValue,
@@ -1325,6 +1390,21 @@ var QueryBuilderImpl = class {
1325
1390
  resolvers: this.resolvers
1326
1391
  };
1327
1392
  }
1393
+ toUpdateQuery() {
1394
+ return {
1395
+ type: "UpdateQuery",
1396
+ conditions: this.serializableConditions(),
1397
+ updates: this.updates ?? {},
1398
+ sort: this.sort,
1399
+ limit: this.limitValue,
1400
+ partition: this.partitionValue ?? null
1401
+ };
1402
+ }
1403
+ toSerializableQueryObject() {
1404
+ const table = this.ensureTable();
1405
+ const payload = this.mode === "update" ? this.toUpdateQuery() : this.toSelectQuery();
1406
+ return { ...payload, table };
1407
+ }
1328
1408
  from(table) {
1329
1409
  this.table = table;
1330
1410
  return this;
@@ -1460,14 +1540,7 @@ var QueryBuilderImpl = class {
1460
1540
  async update() {
1461
1541
  if (this.mode !== "update") throw new Error("Call setUpdates(...) before update().");
1462
1542
  const table = this.ensureTable();
1463
- const update = {
1464
- type: "UpdateQuery",
1465
- conditions: this.conditions,
1466
- updates: this.updates ?? {},
1467
- sort: this.sort,
1468
- limit: this.limitValue,
1469
- partition: this.partitionValue ?? null
1470
- };
1543
+ const update = this.toUpdateQuery();
1471
1544
  return this.db._update(table, update, this.partitionValue);
1472
1545
  }
1473
1546
  onItemAdded(listener) {
@@ -1680,12 +1753,20 @@ var ConditionBuilderImpl = class {
1680
1753
  var c = (field, operator, value) => new ConditionBuilderImpl({ field, operator, value });
1681
1754
  var eq = (field, value) => c(field, "EQUAL", value);
1682
1755
  var neq = (field, value) => c(field, "NOT_EQUAL", value);
1683
- var inOp = (field, values) => c(
1684
- field,
1685
- "IN",
1686
- typeof values === "string" ? values.split(",").map((v) => v.trim()).filter((v) => v.length) : values
1687
- );
1688
- var notIn = (field, values) => c(field, "NOT_IN", values);
1756
+ function inOp(field, values) {
1757
+ const parsed = typeof values === "string" ? values.split(",").map((v) => v.trim()).filter((v) => v.length) : values;
1758
+ return c(field, "IN", parsed);
1759
+ }
1760
+ function within(field, values) {
1761
+ return inOp(field, values);
1762
+ }
1763
+ function notIn(field, values) {
1764
+ const parsed = typeof values === "string" ? values.split(",").map((v) => v.trim()).filter((v) => v.length) : values;
1765
+ return c(field, "NOT_IN", parsed);
1766
+ }
1767
+ function notWithin(field, values) {
1768
+ return notIn(field, values);
1769
+ }
1689
1770
  var between = (field, lower2, upper2) => c(field, "BETWEEN", [lower2, upper2]);
1690
1771
  var gt = (field, value) => c(field, "GREATER_THAN", value);
1691
1772
  var gte = (field, value) => c(field, "GREATER_THAN_EQUAL", value);
@@ -1723,6 +1804,6 @@ var percentile = (attribute, p) => `percentile(${attribute}, ${p})`;
1723
1804
  var sdkName = "@onyx.dev/onyx-database";
1724
1805
  var sdkVersion = "0.1.0";
1725
1806
 
1726
- export { QueryResults, 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 };
1807
+ export { QueryResults, 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 };
1727
1808
  //# sourceMappingURL=index.js.map
1728
1809
  //# sourceMappingURL=index.js.map